difference from dates

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Davide

    difference from dates

    Hi all.

    I'm looking in php.net a function that helps me to work with date.

    I need to build a script wich can calulate the difference from a
    specific date "2007-03-01" to current date.
    I'm thinking about unix epoch, is it the correct way?

    example:

    2007-03-05 - 2007-03-01 = 2 days
    2007-03-05 - 2007-02-05 = 1 month
    etc...

  • Sjoerd

    #2
    Re: difference from dates

    Davide wrote:
    I need to build a script wich can calulate the difference from a
    specific date "2007-03-01" to current date.
    Calculate the difference in seconds (using the Unix epoch) and convert
    that to days, weeks, months.

    Spoiler:

    Comment

    • Toby A Inkster

      #3
      Re: difference from dates

      Davide wrote:
      I need to build a script wich can calulate the difference from a
      specific date "2007-03-01" to current date.
      $old_date = strtotime('2007-03-01');
      $now_date = time();
      $date_diff = $now_date - $old_date;
      printf( "Date difference is %.2f seconds (%.2f days).\n",
      $date_diff,
      $date_diff/(24*60*60) );

      See also:
      Parse about any English textual datetime description into a Unix timestamp


      --
      Toby A Inkster BSc (Hons) ARCS
      Contact Me ~ http://tobyinkster.co.uk/contact
      Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

      * = I'm getting there!

      Comment

      • Tim Roberts

        #4
        Re: difference from dates

        "Davide" <davide.papagno @gmail.comwrote :
        >
        >example:
        >
        >2007-03-05 - 2007-03-01 = 2 days
        >2007-03-05 - 2007-02-05 = 1 month
        >etc...
        Hmmm, in most calendar systems, 2007-03-05 - 2007-03-01 would be 4 days,
        not 2 days...
        --
        Tim Roberts, timr@probo.com
        Providenza & Boekelheide, Inc.

        Comment

        Working...