date diff - please help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dkrysmann@gmail.com

    date diff - please help

    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.

    Thanks
    Darek

  • Kimmo Laine

    #2
    Re: date diff - please help

    <dkrysmann@gmai l.com> wrote in message
    news:1142334289 .015053.249970@ z34g2000cwc.goo glegroups.com.. .[color=blue]
    > 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.[/color]


    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@bhg byrzcv.arg)


    Comment

    • dkrysmann@gmail.com

      #3
      Re: date diff - please help

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

      Comment

      Working...