BoarderLine Posted September 8, 2010 Share Posted September 8, 2010 PHP 5.3.3 I am using this to get a date 6 months from:- $today=date("Y-m-d"); $newdate=strtotime(date("Y-m-d", strtotime($today)) . " +6 months"); However I am getting the output format:- 1299495600 (or similar) The strange thing is this did work with PHP4. Does anyone know why??????????? Cheers Link to comment https://forums.phpfreaks.com/topic/212834-strtowrongtime-issue/ Share on other sites More sharing options...
rwwd Posted September 8, 2010 Share Posted September 8, 2010 Hi there, $newdate = date("Y-m-d", strtotime("+6 months")); That will achieve what you are after, I use a very similar method when setting the time for different time zones, thought there are simpler ways... Cheers, Rw Link to comment https://forums.phpfreaks.com/topic/212834-strtowrongtime-issue/#findComment-1108580 Share on other sites More sharing options...
BoarderLine Posted September 8, 2010 Author Share Posted September 8, 2010 Thanks rwwd, I should have explained a little more about the problem. In the example given I am using $today=date("Y-m-d") however in my code the $today variable can be substituted for any date not just today. So really what I am needing is the strtotime() function to generate +6 months from a dynamic date. Link to comment https://forums.phpfreaks.com/topic/212834-strtowrongtime-issue/#findComment-1108583 Share on other sites More sharing options...
rwwd Posted September 8, 2010 Share Posted September 8, 2010 Strtotime() only returns int:http://uk3.php.net/manual/en/function.strtotime.php so in the context of your example your output would be: 1299495600 (or similar) what you would need then is this:- $today = "Y-m-d"; echo $newdate = date($today, strtotime("+6 months")); Hope that makes sense, Ideally though strtotime is used inside the date() function as the second parameter, purely because it returns an int that the date() function can interpret.. Cheers, Rw Link to comment https://forums.phpfreaks.com/topic/212834-strtowrongtime-issue/#findComment-1108588 Share on other sites More sharing options...
BoarderLine Posted September 8, 2010 Author Share Posted September 8, 2010 hmmmm that just returned the date variable without adding the 6 months....... however thanks I appreciate the assist. I must figure another way Link to comment https://forums.phpfreaks.com/topic/212834-strtowrongtime-issue/#findComment-1108594 Share on other sites More sharing options...
rwwd Posted September 8, 2010 Share Posted September 8, 2010 Works fine for me, locally an server... No problem. Cheers, Rw Link to comment https://forums.phpfreaks.com/topic/212834-strtowrongtime-issue/#findComment-1108598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.