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? Quote Link to comment 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"); Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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; Quote Link to comment Share on other sites More sharing options...
Ihsaan Posted August 28, 2012 Author Share Posted August 28, 2012 2012-08-28 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 ?> Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Ihsaan Posted August 29, 2012 Author Share Posted August 29, 2012 i get a blank page Quote Link to comment 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); 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.