Date addition and subtraction operations in php, and php addition and subtraction operations. For addition and subtraction of dates in php, php addition and subtraction requires: to get another date by adding or subtracting a few days from a date. 1. First, use strtotime () obtain the date's timestamp. php's date addition and subtraction operations, and php's addition and subtraction operations.
Requirement: get another date by adding or subtracting a few days from a date
1. obtain the date timestamp through strtotime ().
2. obtain the timestamp N days ago and use the "current timestamp-N days in seconds = N days ago timestamp"
3. use the date () function to convert the format of the timestamp obtained N days ago.
Example: obtain the date of the previous day from January 1 ,.
// Convert a time point to a timestamp
$ Date = strtotime ('2017-5-1 ');
// Output the date before the day, minus the number of seconds of the day in the timestamp
Echo date ('Y-m-D', $ date-1*24*60*60 );
?>
Output: 2012-4-30
In addition, the time () function obtains the timestamp of the current date!
Latency requirement: increase or subtract a few days from a date to get another date 1. first, obtain the date timestamp through strtotime...