The following example will subtract 2 days from 2016-01-06.
1 2 3 4 5 6 7 8 9 |
$Date = "2016-01-06"; $sub_newdate = date('Y-m-d', strtotime($Date. ' - 2 day')); Adding days into a date $add_newdate = date('Y-m-d', strtotime($Date. ' + 2 day')); echo $sub_newdate; echo '<br/>'; echo $add_newdate; |
The following example will subtract 2 weeks from 2016-01-06.
1 2 3 4 5 6 7 8 9 10 |
$Date = "2016-01-06"; $sub_newdate = date('Y-m-d', strtotime($Date. ' - 2 week')); Adding Weeks into a date $add_newdate = date('Y-m-d', strtotime($Date. ' + 2 week')); echo $sub_newdate; echo '<br/>'; echo $add_newdate; |
The following example will subtract 2 months from 2016-01-06.
1 2 3 4 5 6 7 8 9 10 |
$Date = "2016-01-06"; $sub_newdate = date('Y-m-d', strtotime($Date. ' - 2 month')); Adding months into a date $add_newdate = date('Y-m-d', strtotime($Date. ' + 2 month')); echo $sub_newdate; echo '<br/>'; echo $add_newdate; |
The following example will subtract 2 years from 2016-01-06.
1 2 3 4 5 6 7 8 9 10 |
$Date = "2016-01-06"; $sub_newdate = date('Y-m-d', strtotime($Date. ' - 5 year')); Adding Years into a date $add_newdate = date('Y-m-d', strtotime($Date. ' + 5 year')); echo $sub_newdate; echo '<br/>'; echo $add_newdate; |
Subtracting Years from a date
The following example will subtract 5 years,5 months,5 days from 2016-01-06.
1 2 3 4 5 6 7 8 9 10 |
$Date = "2016-01-06"; $sub_newdate = date('Y-m-d', strtotime($Date. ' - 5 years - 5 months - 5 days')); Adding Years,months,days into a date $add_newdate = date('Y-m-d', strtotime($Date. ' + 5 years + 5 months + 5 days')); echo $sub_newdate; echo '<br/>'; echo $add_newdate; |