PHP gets the start timestamp and end timestamp for today, yesterday, last week, this month

Source: Internet
Author: User

PHP gets the start timestamp and end timestamp of today, yesterday, last week, this month, mainly using PHP's time function mktime. Let's start with a straight-through example to illustrate how to use Mktime to get the start timestamp and end timestamp for today, yesterday, last week, this month, and then introduce the Mktime function and usage.

01//PHP gets today's start timestamp and end timestamp02$beginToday=Mktime(0,0,0,Date(' m '),Date(' d '),Date(' Y '));03$endToday=Mktime(0,0,0,Date(' m '),Date(' d ') +1,Date(' Y ')) -1;04//PHP gets yesterday start timestamp and end timestamp05$beginYesterday=Mktime(0,0,0,Date(' m '),Date(' d ')-1,Date(' Y '));06$endYesterday=Mktime(0,0,0,Date(' m '),Date(' d '),Date(' Y ')) -1;07//PHP gets last week start timestamp and end timestamp08$beginLastweek=Mktime(0,0,0,Date(' m '),Date(' d ')-Date(' W ') +1-7,Date(' Y '));09$endLastweek=Mktime(23,59,59,Date(' m '),Date(' d ')-Date(' W ') +7-7,Date(' Y '));10//PHP gets this month start timestamp and end timestamp11$beginThismonth=Mktime(0,0,0,Date(' m '), 1,Date(' Y '));12$endThismonth=Mktime(23,59,59,Date(' m '),Date(' t '),Date(' Y '));

The PHP mktime () function is used to return a Unix timestamp for a date.

Grammar

Mktime (HOUR,MINUTE,SECOND,MONTH,DAY,YEAR,IS_DST)

Parameters Description
Hour Optional. Specified hours.
Minute Optional. Specify minutes.
Second Optional. Specify seconds.
Month Optional. Specifies the number of months to be represented.
Day Optional. Prescribed days.
Year Optional. Prescribed year. On some systems, the legal value is between 1901-2038. However, there is no such limit in PHP 5.
Is_dst

Optional. If the time is in daylight saving time (DST), set to 1, otherwise set to 0 and if unknown, set to-1.

Since 5.1.0, the IS_DST parameter has been discarded. Therefore, you should use the new Time zone processing feature.

Usage

The parameter always represents the GMT date, so IS_DST has no effect on the result.

Parameters can be left-to-right and empty, and empty parameters will be set to the corresponding current GMT value.

Note that before PHP 5.1, if the argument for the function is illegal, it will return false.

It is also important to note that this function is useful for date arithmetic and validation. It can automatically correct out-of-bounds input, such as:

1    Echo(date("M-d-y",mktime(0,0,0,12,36,2001)));

Output results such as:

jan-05-2002

Two

//Get today 00:00$todaystart=Strtotime(Date(' y-m-d '. 00:00:00 ', Time()));//Get today 24:00$todayend=Strtotime(Date(' y-m-d '. 00:00:00 ', Time() +3600*24));//Count today's registered users$todayuser[' create_time '] =Array(Between, "$todaystart,$todayend");$todaysum=$Users->where ($todayuser),Count();//Get yesterday 00:00$timestart=Strtotime(Date(' y-m-d '. 00:00:00 ', Time() -3600*24));//Get today 00:00$timeend=Strtotime(Date(' y-m-d '. 00:00:00 ', Time()));//statistics of registered users yesterday$map[' create_time '] =Array(Between, "$timestart,$timeend");$daycount=$Users->where ($map),Count();$this->assign ("Todaysum",$todaysum);$this->assign ("Daycount",$daycount);

Reproduced in: https://www.cnblogs.com/rainblack/p/4924581.html

PHP gets the start timestamp and end timestamp for today, yesterday, last week, this month

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.