Home > Backend Development > PHP Tutorial > How to get natural week and natural month in php

How to get natural week and natural month in php

WBOY
Release: 2016-07-06 13:52:56
Original
2200 people have browsed it

The current date is [2016/06/14 Tuesday]

Then the time range last week is [2016/06/06]-[2016/06/12]

Only the current date has not been completed (that is, Sunday this week has not been completed)

Then last week will always be【2016/06/06】-【2016/06/12】

How to get the time range of last week in php

Reply content:

The current date is [2016/06/14 Tuesday]

Then the time range last week is [2016/06/06]-[2016/06/12]

Only the current date has not been completed (that is, Sunday this week has not been completed)

Then last week will always be【2016/06/06】-【2016/06/12】

How to get the time range of last week in php

Use strtotime, check the manual for details. Example date('Y-m-d', strtotime('-1 week')) gets the week before the current time, the month is also date('Y-m-d', strtotime('-1 month')), and the day and year are also available.

echo date("Y-m-d",strtotime('-1 week last monday'))." 00:00:00";
echo date("Y-m-d",strtotime('last sunday'))." 23:59:59";

<code>echo '<br>上周起始时间:<br>';
echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"))),"\n";
echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y"))),"\n";</code>
Copy after login
Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template