Home  >  Article  >  Backend Development  >  PHP Development Notes-Commonly used date acquisition methods in day/week operations_PHP Tutorial

PHP Development Notes-Commonly used date acquisition methods in day/week operations_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:29:21790browse

This Monday
echo date('Y-m-d',(time()-((date('w')==0?7:date('w'))-1) *24*3600)); //w is the numeric form of the day of the week, here 0 is Sunday

This Sunday

echo date('Y-m-d',(time()+(7-(date('w')==0?7:date('w')))*24*3600)); // Also use w to calculate based on the number of days related to Sunday

Last Monday

echo date('Y-m-d',strtotime('-1 monday', time())); //No matter what day it is, -1 monday is the previous valid weekday

Last Sunday

echo date('Y-m-d',strtotime('-1 sunday', time())); //The last valid Sunday, the same applies to other weeks

One day of this month

echo date('Y-m-d',strtotime(date('Y-m', time()).'-01 00:00:00')); //Generate directly from strtotime

Last day of this month

echo date('Y-m-d',strtotime(date('Y-m', time()).'-'.date('t', time()).' 00:00:00') ); //t is the number of days in the month, from 28 to 31 days

The first day of last month

echo date('Y-m-d',strtotime('-1 month', strtotime(date('Y-m', time()).'-01 00:00:00'))); // On the first day of this month, strtotime will be directly increased and subtracted by one month

The last day of the previous month

echo date('Y-m-d',strtotime(date('Y-m', time()).'-01 00:00:00')-86400); //One day minus one day of this month is It’s the last day of last month

Reprinted from http://hi.baidu.com/panez/item/bc88803f487955f2a884289d

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/776509.htmlTechArticleThis Monday echo date('Y-m-d',(time()-((date('w' )==0?7:date('w'))-1)*24*3600)); //w is the numeric form of the day of the week, where 0 is the day of the week echo date('Y-m-d', (time()+(7-(date('w')==0?7...
Statement:
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