Math on dates?
Moderator: General Moderators
Math on dates?
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.
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
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.
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.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Personally I would use MySQL to do the work:
http://www.mysql.com/doc/en/Date_and_ti ... tions.html
Mac
http://www.mysql.com/doc/en/Date_and_ti ... tions.html
Mac