Home > Backend Development > PHP Tutorial > php gets the timestamps from today, yesterday, this week, last week, this month, and in the past three months

php gets the timestamps from today, yesterday, this week, last week, this month, and in the past three months

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-30 13:30:21
Original
1314 people have browsed it

When deleting data, sometimes the timestamp of each time period is needed as the query condition. The following uses the PHP built-in functions mktime() and date() to obtain the timestamp value of each time period:

<?php
    // 今日起止时间
    $beginToday = mktime(0,0,0,date(&#39;m&#39;),date(&#39;d&#39;),date(&#39;y&#39;));
    $now = time();

   &#160;//昨天起至时间
    $beginYesterday = mktime(0,0,0,date(&#39;m&#39;),date(&#39;d&#39;)-1,date(&#39;y&#39;));
    $endYesterday = mktime(0,0,0,date(&#39;m&#39;),date(&#39;d&#39;),date(&#39;y&#39;))-1;

   &#160;//本周起止时间
    $beginThisweek = mktime(0,0,0,date(&#39;m&#39;),date(&#39;d&#39;)-date(&#39;w&#39;)+1,date(&#39;y&#39;));
    $now = time();

   &#160;//上一周起止时间
    $beginLastweek = mktime(0,0,0,date(&#39;m&#39;),date(&#39;d&#39;)-date(&#39;w&#39;)-6,date(&#39;y&#39;));
    $endLastWeek = mktime(23,59,59,date(&#39;m&#39;),date(&#39;d&#39;)-date(&#39;w&#39;),date(&#39;y&#39;));

   &#160;//本月起至时间
    $beginThismonth = mktime(0,0,0,date(&#39;m&#39;),1,date(&#39;y&#39;));
    $now = time();

   &#160;//近三个月起止时间
    $beginLastThreemonth = mktime(0,0,0,date(&#39;m&#39;)-3,1,date(&#39;y&#39;));
    $now = time();
?>
Copy after login


Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces php to get the timestamps from today, yesterday, this week, last week, this month, and the past three months, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Compare JavaScript Date objects
From 1970-01-01 08:00:00
0
0
0
Select rows grouped by date
From 1970-01-01 08:00:00
0
0
0
Hive query: Convert date timestamp to date format
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template