Q:

Write a PHP script to add/subtract the number of days from a particular date

0

Write a PHP script to add/subtract the number of days from a particular date.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
$dt='2011-01-01';
echo 'Original date : '.$dt."\n";
$no_days = 40;
$bdate = strtotime("-".$no_days." days", strtotime($dt));
$adate = strtotime("+".$no_days." days", strtotime($dt));
echo 'Before 40 days : '.date("Y-m-d", $bdate)."\n";
echo 'After  40 days : '.date("Y-m-d", $adate)."\n";
?>

Sample Output:

Original date : 2011-01-01                                  
Before 40 days : 2010-11-22                                 
After  40 days : 2011-02-10

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now