suttercain Posted July 18, 2007 Share Posted July 18, 2007 What's up, what's up? I am trying to use strtotime to convert a date, gathered from a database, and add 21 days to the date. Example: Date from MySQL record is 2007-01-01 I need it to be echoed to the browser as 2007-01-22. Here is what I have now but it just outputs the database date without adding the 21 days. $requested = date('F jS, Y', strtotime($row['letter_requested'])); //Convert to letter requested date $sendBy = strtotime($requested, '+21 day'); echo $sendBy; Link to comment https://forums.phpfreaks.com/topic/60603-solved-strtotime/ Share on other sites More sharing options...
Wildbug Posted July 18, 2007 Share Posted July 18, 2007 I think you have the arguments reversed. Try: strtotime('+21 day', $requested); Alternatively, why not just select it from the database as you need it in your script? SELECT whatever, date, date + INTERVAL 21 DAY AS day21 FROM table WHERE whatever Link to comment https://forums.phpfreaks.com/topic/60603-solved-strtotime/#findComment-301471 Share on other sites More sharing options...
suttercain Posted July 18, 2007 Author Share Posted July 18, 2007 Hi Wildbug, I think you have the arguments reversed. Try: strtotime('+21 day', $requested); I tried the above code and got the following error: Warning: strtotime() expects parameter 2 to be long, string given in C:\wamp\www\ARB\pio\date.php on line 134 Alternatively, why not just select it from the database as you need it in your script? I am using this single mysql query for numerous areas of the page. I don't want to limit the query string in that fashion. Link to comment https://forums.phpfreaks.com/topic/60603-solved-strtotime/#findComment-301475 Share on other sites More sharing options...
paul2463 Posted July 18, 2007 Share Posted July 18, 2007 <?php $requested = strtotime($row['letter_requested']); //dont Convert it to a date at this time $sendBy = strtotime( '+21 day', $requested);//add the 21 days on here echo date('F jS, Y', $sendBy); ?> Link to comment https://forums.phpfreaks.com/topic/60603-solved-strtotime/#findComment-301476 Share on other sites More sharing options...
Wildbug Posted July 18, 2007 Share Posted July 18, 2007 Okay, or this: strtotime("2007-01-01 +21 days"); or strtotime("2007-01-01" . "+21 days"); or strtotime("+21 days",strtotime("2007-01-01")); Link to comment https://forums.phpfreaks.com/topic/60603-solved-strtotime/#findComment-301478 Share on other sites More sharing options...
suttercain Posted July 18, 2007 Author Share Posted July 18, 2007 Nice move by Paul! It worked. Thanks to both of your for the help. SC Link to comment https://forums.phpfreaks.com/topic/60603-solved-strtotime/#findComment-301481 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.