Page 1 of 1
Math on dates?
Posted: Thu Feb 20, 2003 12:13 pm
by uberpolak
Is it possible for PHP to do math on dates? If so how? What I'm looking for is the ability to see how many days ago something was. As I have it now, I'm getting a date string in YYYY-MM-DD format, then subtracting the days, this only works up until there's a months difference. All I can come up with is to make a really big switch doing the appropriate subtraction depending on which month it was, before I do that though I'd like to know if there's a shortcut. I can't find anything in the manual.
Posted: Thu Feb 20, 2003 1:46 pm
by hob_goblin
read
http://www.php.net/strtotime
http://www.devnetwork.net/forums/viewto ... =strtotime
http://www.devnetwork.net/forums/viewto ... =strtotime
strtotime will put your date in a time() format, which can easily have math done to it. then you can use date() to put it back in the format you want.
Posted: Thu Feb 20, 2003 2:49 pm
by uberpolak
Thanks hob, I guess the real problem was that I didn't know where in the manual to look... Works great.
Posted: Thu Feb 20, 2003 6:30 pm
by McGruff
I avoid using mysql date columns when I can: I find it easier to work with timestamps stored in integer cols, then format the output with the date() function.
Posted: Fri Feb 21, 2003 3:46 am
by twigletmac