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; ?> 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. 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 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! 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())); Link to comment https://forums.phpfreaks.com/topic/238010-php-date-calculation/#findComment-1222983 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.