You are here: Re: date diff - please help « PHP Programming Language « IT news, forums, messages
Re: date diff - please help

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]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация