Jump to content

daysPassed() function to compare two dates


thedudeabides

Recommended Posts

I want to do something like this-

 

$days_passed = daysPassed ($last_datetime); //returns (float)number of days (6 hours returns .25 days, 12 hours returns 0.5)

$last_datetime = $getCurrentTime();

 

I will then store $last_datetime in the database for next time.

 

I'm a bit overwhelmed by all the different time and date functions.  Does someone have ready made functions that will work here?

There are a fair few topics around about this, try searching. Here are a few good results.

 

http://www.phpfreaks.com/forums/php-coding-help/date-difference-295142/msg1397605/#msg1397605

http://www.phpfreaks.com/forums/php-coding-help/difference-between-dates-273176/msg1290174/#msg1290174

 

Shouldn't be hard to tailor it to your needs really. Just a matter of converting dates to UNIX timestamp, subtracting then divide that by 60*60*24 (86400, which is 1 day in seconds). Then round, ceil or floor it.

Shouldn't be hard to tailor it to your needs really. Just a matter of converting dates to UNIX timestamp, subtracting then divide that by 60*60*24 (86400, which is 1 day in seconds). Then round, ceil or floor it.

So long as you don't mind it being off by an hour for parts of the year.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.