yandoo Posted July 5, 2009 Share Posted July 5, 2009 Hello im a bit stuck again... Any ideas on how can add a variable number of days (retrieved from database) to a date (also retrieved from database) to give a new date and then output the new date value???? e.g. Both queries i have already retrieve and output the number of days and the SowDate. 84 2009-07-01 <?php echo $row_newtest['LifeTime'];?> <?php echo $row_test['SowDate']; ?> I just need to add the days to the sowdate to give my new date...(which later is inserted a db.) Any help would be be ace! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/164856-solved-add-days-to-a-date/ Share on other sites More sharing options...
SuperBlue Posted July 5, 2009 Share Posted July 5, 2009 This is why you should work with unix timestamps in the database, and only show the dates in readable form when outputted to the browser. Save your dates in the unix format, using php time(); for instance. Then add the number of seconds required, I.e. 86400 for one day. 604800 for one weak. 2629743 for one month. 31556926 for one year. 63113852 for two years. Quote Link to comment https://forums.phpfreaks.com/topic/164856-solved-add-days-to-a-date/#findComment-869291 Share on other sites More sharing options...
johnathanhebert Posted July 5, 2009 Share Posted July 5, 2009 There are lots of ways to do it... here is one way... <?php $utime = strtotime($row_test['SowDate']) + 86400*$row_newtest['LifeTime']) $newdate = date("Y-m-d",$utime); ?> Quote Link to comment https://forums.phpfreaks.com/topic/164856-solved-add-days-to-a-date/#findComment-869294 Share on other sites More sharing options...
yandoo Posted July 5, 2009 Author Share Posted July 5, 2009 Yes I see what you mean and think it will do the job just right...But im getting a parse error with it... ??? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/164856-solved-add-days-to-a-date/#findComment-869306 Share on other sites More sharing options...
johnathanhebert Posted July 5, 2009 Share Posted July 5, 2009 I left a semicolon off the first line... try this... <?php $utime = strtotime($row_test['SowDate']) + 86400*$row_newtest['LifeTime']); $newdate = date("Y-m-d",$utime); ?> Quote Link to comment https://forums.phpfreaks.com/topic/164856-solved-add-days-to-a-date/#findComment-869313 Share on other sites More sharing options...
yandoo Posted July 5, 2009 Author Share Posted July 5, 2009 Hi there, I totally see what you mean thats brilliant thank you.. I added ( and ; .... It works like a charm.. Thank You Quote Link to comment https://forums.phpfreaks.com/topic/164856-solved-add-days-to-a-date/#findComment-869314 Share on other sites More sharing options...
yandoo Posted July 5, 2009 Author Share Posted July 5, 2009 Thanks for reply again... we got it! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/164856-solved-add-days-to-a-date/#findComment-869315 Share on other sites More sharing options...
Daniel0 Posted July 5, 2009 Share Posted July 5, 2009 31556926 for one year. 63113852 for two years. Not if it's a leap year. Quote Link to comment https://forums.phpfreaks.com/topic/164856-solved-add-days-to-a-date/#findComment-869323 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.