Add and subtract within 10 PHP date plus subtraction operation implementation code

Source: Internet
Author: User
Tags echo date
1, first through Strtotime () to obtain the date timestamp
2, get the time stamp N days ago, through the "current timestamp-n days of the number of seconds = n days before the time stamp"
3, to n days before the time stamp with the date () function for format conversion
The following example: Date of the day before the 2012-5-1 number was obtained

Copy the Code code as follows:


Convert a point in time to a timestamp
$date = Strtotime (' 2012-5-1 ');
Output the date of the day, minus the number of seconds in a day on 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 addition and subtraction of PHP within 10 of the date plus subtraction operation implementation code, including the content of the addition and subtraction within 10, I hope to be interested in PHP tutorial friends helpful.

  • Related Article

    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.