Ihsaan Posted August 28, 2012 Share Posted August 28, 2012 I have a variable setup to contain $created_date but now i need to create another variable to contain $due_date which is 30 days after the $created_date. How would i achieve this? Link to comment https://forums.phpfreaks.com/topic/267687-due-date-plus-x-days/ Share on other sites More sharing options...
darkfreaks Posted August 28, 2012 Share Posted August 28, 2012 like this.... $date = date("Y-m-d");// current date $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day"); $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 week"); $date = strtotime(date("Y-m-d", strtotime($date)) . " +2 week"); $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 month"); $date = strtotime(date("Y-m-d", strtotime($date)) . " +30 days"); Link to comment https://forums.phpfreaks.com/topic/267687-due-date-plus-x-days/#findComment-1373123 Share on other sites More sharing options...
Barand Posted August 28, 2012 Share Posted August 28, 2012 Assuming $created_date is YYYY-MM-DD format $due_date = date ('Y-m-d', strtottime("+30 days $created_date")); If dates are Unix time values $due_date = strtotime('+30 days' , $created_date); Or if you are pulling created_date from a DB table SELECT created_date + INTERVAL 30 DAY as due_date Link to comment https://forums.phpfreaks.com/topic/267687-due-date-plus-x-days/#findComment-1373136 Share on other sites More sharing options...
Ihsaan Posted August 28, 2012 Author Share Posted August 28, 2012 Thanks guys for your quick response but something seems to be wrong. Here is the code on the page $date_created = $_POST['date_created']; $date_due = date('Y-m-d', strtottime('+30 days $date_created')); Doesn't work? Any suggestions? Link to comment https://forums.phpfreaks.com/topic/267687-due-date-plus-x-days/#findComment-1373146 Share on other sites More sharing options...
Barand Posted August 28, 2012 Share Posted August 28, 2012 What does $date_created contain? echo $date_created; Link to comment https://forums.phpfreaks.com/topic/267687-due-date-plus-x-days/#findComment-1373147 Share on other sites More sharing options...
Ihsaan Posted August 28, 2012 Author Share Posted August 28, 2012 2012-08-28 Link to comment https://forums.phpfreaks.com/topic/267687-due-date-plus-x-days/#findComment-1373149 Share on other sites More sharing options...
Barand Posted August 28, 2012 Share Posted August 28, 2012 You need double quotes and the function is strtotime, not strtoTtime Link to comment https://forums.phpfreaks.com/topic/267687-due-date-plus-x-days/#findComment-1373150 Share on other sites More sharing options...
Ihsaan Posted August 28, 2012 Author Share Posted August 28, 2012 check line 50 - http://codeviewer.org/view/code:293f Link to comment https://forums.phpfreaks.com/topic/267687-due-date-plus-x-days/#findComment-1373153 Share on other sites More sharing options...
Barand Posted August 28, 2012 Share Posted August 28, 2012 <?php $date_created = '2012-08-28'; $date_due = date('Y-m-d', strtotime("+30 days $date_created")); echo $date_due ; //---> 2012-09-27 ?> Link to comment https://forums.phpfreaks.com/topic/267687-due-date-plus-x-days/#findComment-1373154 Share on other sites More sharing options...
Ihsaan Posted August 28, 2012 Author Share Posted August 28, 2012 Not working Did you have a look at the code? Link to comment https://forums.phpfreaks.com/topic/267687-due-date-plus-x-days/#findComment-1373155 Share on other sites More sharing options...
Barand Posted August 28, 2012 Share Posted August 28, 2012 yes. I gave you the correct code. You are using $created_date. Link to comment https://forums.phpfreaks.com/topic/267687-due-date-plus-x-days/#findComment-1373156 Share on other sites More sharing options...
Ihsaan Posted August 28, 2012 Author Share Posted August 28, 2012 Fixed the $date_created still does not work... Will play around again later tonight maybe im missing something else. Thanks alot Barand Link to comment https://forums.phpfreaks.com/topic/267687-due-date-plus-x-days/#findComment-1373174 Share on other sites More sharing options...
jazzman1 Posted August 28, 2012 Share Posted August 28, 2012 Perhaps, you have an error somewhere in your script. Copy/paste Barand's code and tell us what a result you get it. $date_created = '2012-08-28'; $date_due = date('Y-m-d', strtotime("+30 days $date_created")); echo $date_due ; //---> 2012-09-27 Link to comment https://forums.phpfreaks.com/topic/267687-due-date-plus-x-days/#findComment-1373179 Share on other sites More sharing options...
Ihsaan Posted August 29, 2012 Author Share Posted August 29, 2012 i get a blank page Link to comment https://forums.phpfreaks.com/topic/267687-due-date-plus-x-days/#findComment-1373489 Share on other sites More sharing options...
Barand Posted August 29, 2012 Share Posted August 29, 2012 try it with error reporting turned on. At top of script put ini_set('display_errors',1); error_reporting(-1); Link to comment https://forums.phpfreaks.com/topic/267687-due-date-plus-x-days/#findComment-1373498 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.