joesaddigh Posted July 15, 2009 Share Posted July 15, 2009 Hi, I am having a problem which i think is probably quite simple to solve but I cant seem to do it. I am trying to add weeks or days to a date (not todays date) I have a date variable and I want to add a duration variable to it> The code I have is as follows. echo 'The original date is ' . $sqldate; echo '<br />'; echo '<br />'; $sqldate = strtotime("+2 days"); echo 'The new date is ' . $sqldate = date($sqldate); $sqldate contains this value 2009-08-17 Thanks Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted July 15, 2009 Share Posted July 15, 2009 Simply do like strtotime($sqldate . ' +2 days'); The variable you pass to it must of course be a valid date for strtotime. Quote Link to comment Share on other sites More sharing options...
joesaddigh Posted July 15, 2009 Author Share Posted July 15, 2009 Ok that works but I want to keep it as a date and add two days to it is that possible. If not how could I then turn the string back to a date format as a specified Y-mm-dd Cheers Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted July 15, 2009 Share Posted July 15, 2009 strtotime() will return a UNIX timestamp. You can use date to (re)format it. So that would be: date('Y-m-d', strtotime($sqldate . ' +2 days')); Quote Link to comment Share on other sites More sharing options...
joesaddigh Posted July 15, 2009 Author Share Posted July 15, 2009 THANKS!! Works perfect. Should have got that one but appreciate your help very much! 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.