|
Posted by Kimmo Laine on 03/14/06 13:21
<dkrysmann@gmail.com> wrote in message
news:1142334289.015053.249970@z34g2000cwc.googlegroups.com...
> Hi,
> I'm very new to this group and the php, now I've question about date
> function.
>
> 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.
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
simply:
$diff = $today - $created;
Now just do the math to convert the seconds to days, hours, minutes. Just
divide it by 60, 60, 24 etc.
HTH
--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviφ
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)
Navigation:
[Reply to this message]
|