If I have a date in the past and I need to tell which year (15th, 23rd year etc.) it is now, how do I do that?
Eg. Jan 20, 1995 -- now is 14th year.
so subtract
SELECT YEAR(NOW())-YEAR(date_field) as year_diff from foo
I can't use db in this code. The date is provided as a var (any format, whichever works best for this calculation).
$date="Jan 20, 1995"; echo date("Y") - date("Y",strtotime($date));
Are you sure? Shouldn't it take into consideration the anniversary date? Before Jan.20 it'll be 13th year, on or after Jan. 20 it'll be already 14th year...
$date="Jan 20, 1995"; $now=time(); echo round(($now - strtotime($date)) / (60*60*24*365),0);
there will be leap second and other issues, but that's all i have time for.