Subtract Dates in PHP

Subtract Dates in PHP” post has been moved to:
http://www.axdimensions.com/pixelnotes/2007/11/23/subtract-dates-in-php/

Thanks, Em

About these ads

~ by Em on November 23, 2007.

14 Responses to “Subtract Dates in PHP”

  1. …. hmmmm…. what abt finding in days,years,decade,centuries… :p

  2. >> echo $date_diff . ” days”;
    ..shows the data in days ;)

    And yea, divide by n*365*86400 (where n = # of years) and it will answer your “years,decade,centuries” :p

    Enjoy! (=

  3. thanks for the prompt reply….. it “helped” me so much…. i was trying for it like days.. wasnt able to figure it out…. thanks to you…:p:p:p:p

  4. hey this sounds cool, but mussu iss mein we have to define the dates pehlay se?? whats the dynamic part??

  5. The result is dependent upon the input that can be dynamic/static ;)

  6. YOU ARE A GODSEND, been trying to write my own lengthy function to do this and it was off by about a week on large counts. this is precise. THANKS!

  7. Glad to hear that :D

  8. meehn, thanks a lot. been lookin for something like this since.. pity ur link was on page 3 google for my keyword.

    thanks

  9. There are 366 days in a leap year. Your function will be off a day if you span one leap year in your date range; even more days the more leap years you span. So your function is only good for time frames within 365 days of each other.

  10. Try..
    $date_diff = subtract_dates(“2007-11-5″, “2008-11-5″);
    //output: 366 days

    Where as,
    $date_diff = subtract_dates(“2006-11-5″, “2007-11-5″);
    //returns: 365 days

    The leap year case seems to be working fine.

  11. Em said this on November 23, 2007 at 9:21 pm
    “And yea, divide by n*365*86400 (where n = # of years) and it will answer your “years,decade,centuries” :p”

    Sorry, I was referring to the above; when you want to output into years. You can’t count on 365 days as a standard year or you’ll be off when you break it down into # years, # months, # days. After searching around, I found a great function that accounts for leap years on php.net/datetime by a user nate at example dot com. But for only breaking down into days, your function works just fine.

  12. I Agree. The above function would work only if one desire to find number of days. To calculate in years etc., we’ll have to look up for something else. :)

    Though I was only messing with my friend over the above statements! ;)

  13. This code works like a charm. Thanks.

  14. THANKS BUDDY!! WAS HARDLY IN SEARCH OF IT….

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: