orange08 Posted December 27, 2008 Share Posted December 27, 2008 currently, i 'm working with a date and intend to add a specific month to the date, so that the date that is added with the month can be generated... e.g. 2008-12-27 add 1 month then the generated date which i needed is 2009-1-27 after searching online, i found strtotime(), but i'm quite confuse with it and unable to get the answer i want... so really hope that sifu here can give me a hand, thx! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 27, 2008 Share Posted December 27, 2008 Here's a quick example: <?php echo date('Y-m-d',strtotime('2008-12-27 +1 month')); ?> Ken Quote Link to comment Share on other sites More sharing options...
orange08 Posted December 27, 2008 Author Share Posted December 27, 2008 Here's a quick example: <?php echo date('Y-m-d',strtotime('2008-12-27 +1 month')); ?> Ken yes, thx! it works. but, how about if my date and month to add is in variable, how to apply it? $mydate=2008-12-27; $addmth=1; i tried, but the answer is wrong, year 1970 is generated, month and day are wrong too... Quote Link to comment Share on other sites More sharing options...
RussellReal Posted December 27, 2008 Share Posted December 27, 2008 <?php echo date('Y-m-d',strtotime('2008-12-27 +1 month')); ?> this should be what you'd probably want <?php echo date('Y-m-d',strtotime("{$mydate} +{$addmth} month")); ?> Quote Link to comment Share on other sites More sharing options...
orange08 Posted December 27, 2008 Author Share Posted December 27, 2008 <?php echo date('Y-m-d',strtotime('2008-12-27 +1 month')); ?> this should be what you'd probably want <?php echo date('Y-m-d',strtotime("{$mydate} +{$addmth} month")); ?> i try this <?php $jdate=$_SESSION['StartDate']; $m=$_SESSION['Duration']; echo date('Y-m-d',strtotime($jdate.'+'.$m .'month')); ?> and currently it works, what do you think? will it create problem? Quote Link to comment Share on other sites More sharing options...
RussellReal Posted December 27, 2008 Share Posted December 27, 2008 eh, idk lol, just use this to be on the safe side: <?php $jdate=$_SESSION['StartDate']; $m=$_SESSION['Duration']; echo date('Y-m-d',strtotime("{$jdate} +{$m} month")); ?> but they're both the same basically, except yours is missing plenty whitespace lol and idk if eventually that will bose a problem so.. Quote Link to comment Share on other sites More sharing options...
orange08 Posted December 27, 2008 Author Share Posted December 27, 2008 eh, idk lol, just use this to be on the safe side: <?php $jdate=$_SESSION['StartDate']; $m=$_SESSION['Duration']; echo date('Y-m-d',strtotime("{$jdate} +{$m} month")); ?> but they're both the same basically, except yours is missing plenty whitespace lol and idk if eventually that will bose a problem so.. ok, thx! i'll take your advice! Quote Link to comment 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.