Date addition and subtraction operations in php, php addition and subtraction operations _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.