• Advertisement
Sign in to follow this  

[web] Number of Days between two Dates

This topic is 4469 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If I have a mysql time/date stamp (in the format of YYYY-MM-DD HH:MM:SS), and I want to see how many days have passed between todays current date and the time stamp (The time part of the stamp doesn't need to be evaulated, just the date). Is there any easy way of doing this in PHP? I've googled it a few times, and I started running into functions that required me to check for leap year.... so I've decided to ask around before attempting to modify such a function for my needs. Anyways, thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
I've always made it habit to check for leap year, otherwise your value could be a day off every fourth year, since 1970(unix time) or otherwise you should still do it as a 'just in case'.

Share this post


Link to post
Share on other sites
mySQL has TIMEDIFF( time1, time2 ) function. this would best to use

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

to convert from mysql timestamp to unix timestamp without mysql:
http://devcorner.georgievi.net/articles/php/phpdatetotimestamp/

Share this post


Link to post
Share on other sites
Ok.. I found my answer. The trick is to do it like this:

SELECT *, DateDiff(LastLogin, Now( )) AS Diff FROM UserStats where Username = '$UserName';

Where LastLogin is a column containing the date/time of the last login. The 'Diff' column will contain the difference in terms of number of days. Very useful :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement