简体   繁体   English

在php中获取当前的第一天和最后一天

[英]Grab current first and last day in week in php

How do I grab and show dates for the first and last day in the current week we're in. 如何获取和显示我们所在的本周第一天和最后一天的日期。

So in this current week it would output: 因此,在本周中它将输出:

2012-05-14  -  2012-05-20

(It's 2012-05-17 today) (今天是2012-05-17)

How can this be done simply? 如何简单地做到这一点?

try use strtotime 尝试使用strtotime

$first = date('Y-m-d',strtotime("last monday"));
$last = date('Y-m-d',strtotime("next sunday"));

other examples 其他例子

strtotime('monday this week');
strtotime('sunday this week');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM