Jump to content

daysPassed() function to compare two dates


thedudeabides
 Share

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.