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

“Subtract Dates in PHP” post has been moved to:
http://www.axdimensions.com/pixelnotes/2007/11/23/subtract-dates-in-php/
Thanks, Em
…. hmmmm…. what abt finding in days,years,decade,centuries… :p
>> 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! (=
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
hey this sounds cool, but mussu iss mein we have to define the dates pehlay se?? whats the dynamic part??
The result is dependent upon the input that can be dynamic/static
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!
Glad to hear that
meehn, thanks a lot. been lookin for something like this since.. pity ur link was on page 3 google for my keyword.
thanks
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.
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.
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.
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!
This code works like a charm. Thanks.
THANKS BUDDY!! WAS HARDLY IN SEARCH OF IT….