c_pattle Posted July 8, 2011 Share Posted July 8, 2011 I have a variable that stored the date $date = date("Y-m-d"); If I want to deduct or add days to this so I get a date in the past or future is there an easy way to do this or do I have to convert it to a timestamp then convert it back etc? Quote Link to comment https://forums.phpfreaks.com/topic/241420-php-date-help/ Share on other sites More sharing options...
Psycho Posted July 8, 2011 Share Posted July 8, 2011 See the manual for strtotime(): http://us2.php.net/manual/en/function.strtotime.php Here is a quick example of how you could get the date 5 days in the future of the $date value //Longform $newDateTimestamp = strtotime("$date +5 days"); $newDateString = date("Y-m-d", $newDateTimestamp); //Shortform $newDateString = date("Y-m-d", strtotime("$date +5 days")); Quote Link to comment https://forums.phpfreaks.com/topic/241420-php-date-help/#findComment-1240131 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.