SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast bokz_42's Avatar
    Join Date
    Sep 2006
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date Calculation

    Hello guys,

    I have a little situation that involves date calculation.

    Lets say the given date is from January 5, 2009 to March 23, 2009

    How can i calculate that from January 5 to January 31 is 27 days(include Jan 5) and
    from Feb 1 to feb 28 is 28 days and
    from march 1 to march 23 is 23 days???

    Sorry but i'm a little confused and still more to learn


    Thanks alot and more power!

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Use strtotime() to convert the dates into timestamps (numbers of seconds)

    Then subtract to get the number of seconds between the two dates

    Divide that by 60 to get the number of minutes
    Divide that by 60 to get the number of hours
    Divide that by 24 to get the number of days

    PHP Code:
    $date1 "January 5, 2009";
    $date2 "March 23, 2009";
    $difference strtotime($date2) - strtotime($date1);
    echo 
    "Number of days: " . ($difference 60 60 24); 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •