Home > Backend Development > PHP Tutorial > 打印前一周的每一天

打印前一周的每一天

WBOY
Release: 2016-06-23 14:38:27
Original
1032 people have browsed it

$week_start = date("U",mktime(0,0,0,date("m"),date("d")-7,date("Y")));$week_end = date("U",mktime(23,59,59,date("m"),date("d")-0,date("Y")));$date=date('Y-m-d',$week_start);$date1=date('Y-m-d',$week_end);
Copy after login

写到这里不知道该怎么写了。
我想用for循环写可是判断条件不知道怎么写了。。怎么才能把每一天的日期打印出来啊


回复讨论(解决方案)

这是我看到别人收藏的文章中的一部分。你自己去变通一下
echo "今天:".date("Y-m-d")."
";
echo "昨天:".date("Y-m-d",strtotime("-1 day")), "
";
echo "明天:".date("Y-m-d",strtotime("+1 day")). "
";

echo "一周后:".date("Y-m-d",strtotime("+1 week")). "
";
echo "一周零两天四小时两秒后:".date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")). "
";
echo "下个星期四:".date("Y-m-d",strtotime("next Thursday")). "
";
echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."
";
echo "一个月前:".date("Y-m-d",strtotime("last month"))."
";
echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."
";
echo "十年后:".date("Y-m-d",strtotime("+10 year"))."
";

	$week_start = strtotime(date('Y-m-d',strtotime('-6 day')));	$week_end=strtotime(date('Y-m-d',time()));	for($i=$week_start; $i<=$week_end; $i+=86400)	{		echo date('Y-m-d',$i).'<br>';	}
Copy after login

2013-11-23
2013-11-24
2013-11-25
2013-11-26
2013-11-27
2013-11-28
2013-11-29

for($i=7; $i>=0; $i--){    echo date('Y-m-d',strtotime("-$i day")).'<br>';}
Copy after login

2013-11-22
2013-11-23
2013-11-24
2013-11-25
2013-11-26
2013-11-27
2013-11-28
2013-11-29

<?php//上个礼拜一$n = strtotime("last week");$timestrap = 86400;for ($i=0; $i<7; $i++){    echo date('Y-m-d', $n+($i*$timestrap)),'<br />';}?>
Copy after login

Related labels:
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