Home > Backend Development > PHP Tutorial > Addition and subtraction within 10. Implementation code for date addition and subtraction operations in PHP

Addition and subtraction within 10. Implementation code for date addition and subtraction operations in PHP

WBOY
Release: 2016-07-29 08:47:28
Original
1656 people have browsed it

1. First get the timestamp of the date through strtotime()
2. Get the timestamp N days ago, through "current timestamp - seconds in N days = timestamp N days ago"
3. Get the timestamp N days ago The timestamp is formatted using the date() function.
Example below: Get the date one day before 2012-5-1

Copy the code The code is as follows:


//Convert the time point For the timestamp
$date = strtotime('2012-5-1');
//Output the date one day ago, subtract the number of seconds of the day from the timestamp
echo date('Y-m-d',$date - 1*24*60*60);
?>


Output: 2012-4-30
In addition, the time() function gets the timestamp of the current date!

The above introduces the code for adding and subtracting dates within 10 in PHP, including the content of addition and subtraction within 10. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template