PHP gets a summary of various times (code)

Source: Internet
Author: User
This article brings you the content is about PHP to obtain a variety of time summary (code), there is a certain reference value, the need for friends can refer to, I hope to help you.

Get system time

Such as: The day before the system, the current time of the week Monday time, etc.

1. Get the current time of the system

echo "Date (' y-m-d ', Time ())";

2. Get the System one day before the time

echo "Date" ("Y-m-d", Strtotime ("-1 Day")) "; Minus (-) a few days before it takes a few days to add (+)

3. Get current system time last week of Monday and Sunday of the day

The date of last Sunday is $lastsunday = Date (' y-m-d ', Strtotime ('-1 Sunday ', Time ())),///based on the time difference minus 6 days ago, calculated last week 1st period $lastmonday = Date (' y-m-d ', Strtotime (' $lastSunday-6 day ', $SS));

4. Get the day of the current week Sunday is 0 weeks a to Saturday is 1-6

    $today = Date (' y-m-d ', Time ());    Gets the day ordinal of the current week Sunday is 0 weeks a to Saturday is 1-6      $w =date (' W ', Strtotime ($today));      $first =1;    Gets the start date of the week, if $w is 0, then represents Sunday, minus 6 days         $weekStart =date (' y-m-d 00:00:00 ', Strtotime ("$today-". $w? $w-$first: 6). ' Days ');                This week's end date      $weekEnd =date (' y-m-d 23:59:59 ', Strtotime ("$weekStart +6 Days");    The start time of the previous week    $weekStart = Date (' y-m-d 00:00:00 ', Strtotime ("$weekStart-7 Days");    $weekEnd = Date (' y-m-d 23:59:59 ', Strtotime ("$weekEnd-7 Days")););

5. How many days in the last one months

$t = date (' t ', Strtotime ('-1 month '));

Related recommendations:

Implementation code of FTP upload and download function in PHP

PHP implementation of File upload and download method (code)

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.