date diff - please help

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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

Quoted text here. Click to load it

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 | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)  

Re: date diff - please help

thanks a lot, I was not expecting this quick answer.

Site Timeline