wilna Posted May 31, 2011 Share Posted May 31, 2011 Hi I don't understand what I'm doing wrong, I want to subtract 6 months from my date, but I get 1969/07 as an answer? <?php $date = date('Y/m'); echo $date; echo "<br/>"; $date1 = date ("Y/m", strtotime("-6 month", strtotime($date))); echo $date1; ?> Quote Link to comment https://forums.phpfreaks.com/topic/238010-php-date-calculation/ Share on other sites More sharing options...
George Botley Posted May 31, 2011 Share Posted May 31, 2011 Hello, The best way to do this is to provide a timestamp. See the below $date1 = date(Y/m", strtotime("-6 months", time())); A timestamp is the current time in seconds using the UNIX system. Quote Link to comment https://forums.phpfreaks.com/topic/238010-php-date-calculation/#findComment-1222969 Share on other sites More sharing options...
QuickOldCar Posted May 31, 2011 Share Posted May 31, 2011 <?php $date = date('Y/m'); echo $date; echo "<br/>"; $date1 = date("Y/m", strtotime("-6 month")); echo $date1; ?> Results: 2011/05 2010/12 Quote Link to comment https://forums.phpfreaks.com/topic/238010-php-date-calculation/#findComment-1222977 Share on other sites More sharing options...
wilna Posted May 31, 2011 Author Share Posted May 31, 2011 Thank you George! Quote Link to comment https://forums.phpfreaks.com/topic/238010-php-date-calculation/#findComment-1222979 Share on other sites More sharing options...
QuickOldCar Posted May 31, 2011 Share Posted May 31, 2011 There was a quote missing george. $date1 = date("Y/m", strtotime("-6 months", time())); Quote Link to comment https://forums.phpfreaks.com/topic/238010-php-date-calculation/#findComment-1222983 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.