Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2005
    Location
    Louisville, Kentucky
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Finding the diffrence between two dates.

    I'm currently using this little block of code here to find the diffrence (in days) between the current date, and the date of the new year
    PHP Code:
    $date_new_year strtotime("1 January 2006");
    $current_date time();
    $days_left $date_new_year $days_left;
    print 
    "Days left until new year's: ";
    print 
    date("d"$days_left); 
    I'm not sure if this is valid, is there a function that allows me to get the exact days, months, years, hours, minutes and even seconds from a specifc date to the current date? Thanks for reading.
    What was I thinking?
    Email Me

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    PHP Code:
    $start_date '2005-12-31';
    $end_date '2006-06-03';

    $start_ts strtotime($start_date);
    $end_ts strtotime($end_date);
    $count 0;
    while (
    $start_ts $end_ts)
    {
        
    $start_ts strtotime(date('Y-m-d'$start_ts) . ' +1 day');
        
    $count++;    
    }
    echo 
    $count

  • #3
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    $date_new_year 
    strtotime("1 January 2006");
    $current_date time();
    $days_left $date_new_year $current_date;
    echo 
    'Days left until new years: ' $days_left 60 60 24;
    ?>
    If you want hours and such instead of a decimal you'll have to calculate it out further.
    "$question = ( to() ) ? be() : ~be();"

  • #4
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    Quote Originally Posted by Velox Letum
    PHP Code:
    ...echo 'Days left until new years: ' $days_left 60 60 24
    ...and what about the days of the year that are not 60x60x24 seconds long?


  •  

    Posting Permissions

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