Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- date diff - please help
March 14, 2006, 11:04 am
rate this thread
I'm very new to this group and the php, now I've question about date
I need function how to calculate time diffrence between two dates.
First date: $rs['lastBuildDate' is like 'March 6, 2006 10:04 am' next
date have to be today.
The expected output number of days and hours.
Later on I will add some If statements if days > 1 then 1day.gif etc.
This is required to my web based rss agregator.
Re: date diff - please help
First you need to convert both days into timestamps, which are much easier
to deal with. you get todays timestamp from mktime(); to convert the textual
date representation into a timestamp you could use strtotime().
the code would look like this:
$today = mktime();
$created = strtotime($rs['lastBuildDate']); // This is the March 6...
now that you have both dates as timestamps, their difference in seconds is
$diff = $today - $created;
Now just do the math to convert the seconds to days, hours, minutes. Just
divide it by 60, 60, 24 etc.
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirvi
firstname.lastname@example.org | Gedoon-S @ IRCnet | rot13(email@example.com)
- » Losing one session vatiable, rest are still intact (repost)
- — Previous thread in » PHP Scripting Forum