bsamson Posted June 28, 2008 Share Posted June 28, 2008 Hey ALL! I know how to add days to the current date, <?php echo "15 Days from today is: ".date("m/d/Y", strtotime("+15 days"); ?> How do I calculate 15 days from today when the user inputs the date (i.e. Not today) example: 06/02/2008 + 15 days Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/112329-stupid-question-about-date-calculations/ Share on other sites More sharing options...
br0ken Posted June 28, 2008 Share Posted June 28, 2008 You might have to change this slightly depending on the format you're using for dates. $date = "06282008"; // Todays date $month = substr($date, 0, 2); $day = substr($date, 2, 2); $year = substr($date, 4, 4); echo date("m/d/Y", mktime(1, 1, 1, $month, ($day+15), $year)); If this confuses you just read up on the mktime() PHP function and should be clear. Link to comment https://forums.phpfreaks.com/topic/112329-stupid-question-about-date-calculations/#findComment-576698 Share on other sites More sharing options...
PFMaBiSmAd Posted June 28, 2008 Share Posted June 28, 2008 strtotime can do this as long as the existing date is in a format it understands. For your mm/dd/yyyy example - <?php echo "15 Days from 06/02/2008 is: ".date("m/d/Y", strtotime("06/02/2008 + 15 days")); ?> Link to comment https://forums.phpfreaks.com/topic/112329-stupid-question-about-date-calculations/#findComment-576713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.