If I have 2 dates..
$date1 = date("m/d/Y", strtotime($selected_date)); $date2 = date("m/d/Y", strtotime($lgb_date_raw));
How would I determine the number of days they differ?
I tried something like..
$diff_date = $date1 - $date2;
But all I got was the differnese in MONTHS, not days.
/this is non tested code, used for example only but it should work/
#get two unix time stamps(seconds from 1/1/1970 $date1 = strtotime($selected_date); $date2 = strtotime($lgb_date_raw); $diff = $date1 - $date2; $sec = $diff % 60; $diff = ($diff -$sec) / 60; $min = $diff % 60; $diff = ($diff - $min)/60; $hour = $diff % 24; $diff = ($diff - $hours)/24 /should equal days. if you continue the pattern you could get weeks, or months or years/
if you want to know why it gave you monthes? the minus sign is a math(numbers) opperator. date() returns a string. so php guesses at what that sring should be as a number. to quote the php manual
http://phpbuilder.com/manual/language.types.string.php
"The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used. "
Another example of non psychic coding.
GREAT that works perfectly, thanks so much!
One more question. 🙂
The number I'm getting in $diff is something like "50.041666666667"
How do I drop everything after the '.' for display purposes?
strtok(".", $diff); or substr($diff, 0, strpos($diff,"."));
agian, these should work. but are untested. though you shouln't get a trailing decimal, or for that matter any decimal at all.
i guess there is an error in my algorithim.