Php time computing problem summary _ php skills

Source: Internet
Author: User
Tags echo date
This article mainly introduces the related issues of php time computing, and summarizes and analyzes common php operation skills on time and date in the form of examples, which has some reference value, for more information about php time computing, see the examples in this article. We will share this with you for your reference. The details are as follows:

1. php obtains the date three months ago.

<? Php header ("content-Type: text/html; charset = utf-8");?> <? Php $ s_sdate = date ("Y-m-d"); // Current Time $ moth_day = 90; // month (converted to days) $ s_edate = date ("Y-m-d", (strtotime ($ s_sdate)-$ moth_day * 84600); echo $ moth_day. the date before ". $ s_edate;?>

2. 30 days after the calculation date

You can use strtotime PHP to provide a super simple way to complete the work of dozens of lines of code.

First convert a date to a UNIX timestamp

$ T = time (); // Current timestamp $ t = strtotime ("+ 30 days", $ t ); // 30 days later, the timestamp echo date ("Y-m-d", $ t); // format the date

3. convert the timestamp of 2 days... then subtract

$ T1 = strtotime ("2009-08-19"); $ t2 = strtotime ("2009-08-20"); $ t = $ t2-$ t1; // second echo (int) for days of difference) ($ t/86400)

4. determine whether it is this week

$ Date = "2008-12-08"; if (isCurrentWeeks ($ date) {echo $ date. "Is this week";} else {echo $ date. "Not this week";} function isCurrentWeeks ($ d) {return (date ("W", strtotime ($ d) = date ("W ", strtotime ("now ")));}

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.