Home > Article > Backend Development > php gets the timestamps from today, yesterday, this week, last week, this month, and in the past three months
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('m'),date('d'),date('y')); $now = time();  //昨天起至时间 $beginYesterday = mktime(0,0,0,date('m'),date('d')-1,date('y')); $endYesterday = mktime(0,0,0,date('m'),date('d'),date('y'))-1;  //本周起止时间 $beginThisweek = mktime(0,0,0,date('m'),date('d')-date('w')+1,date('y')); $now = time();  //上一周起止时间 $beginLastweek = mktime(0,0,0,date('m'),date('d')-date('w')-6,date('y')); $endLastWeek = mktime(23,59,59,date('m'),date('d')-date('w'),date('y'));  //本月起至时间 $beginThismonth = mktime(0,0,0,date('m'),1,date('y')); $now = time();  //近三个月起止时间 $beginLastThreemonth = mktime(0,0,0,date('m')-3,1,date('y')); $now = time(); ?>
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.