i'm trying to make a script to calculate the diference between two dates, but in minutes, the thing is that i need to remove from mysql database all the entries that has mora than 15 minutes on the database, i'm planing to run the script in background using the cron jobs, but the main problem is that i don't know how to get the minutes from the two dates, i tried using

$mins = date_diff(date("Y-m-d H:i:s"), $rows["hora"]);

but the php told that the first parameter is a string

any help will be very appreciatted

thanks in advanced for all the help.

Recommended Answers

All 3 Replies

Member Avatar for LastMitch

@daimaku

how calculate minute diference between two dates

Try this:

$to_time = strtotime("2012-10-24 12:00:00");
$from_time = strtotime("2012-10-24 11:54:00");
echo round(abs($to_time - $from_time) / 60,2). " minute";

or read and try this:

http://www.if-not-true-then-false.com/2010/php-calculate-real-differences-between-two-dates-or-timestamps/

commented: To Rectify what some retard did to LastMitch +0

thanks LastMitch it works perfect, thank you very much!!!

Member Avatar for LastMitch

@daimaku

It's great to hear that you solve it! Can you click Mark Question Solve on the bottom left corner so the thread is close and solve so noone can add stuff to it. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.