[英]display last days of previous month php
I searched the millions of similar posts about this but cannot find how to make it count down from 31, 30, 29, 28 etc. 我搜索了数以百万计的与此相关的类似帖子,但找不到如何将其从31、30、29、28等倒计数。
I can have the previous calendar blocks show the 31st but that's all. 我可以让前面的日历块显示31号,仅此而已。 I need it to show previous month 31st, 30, 29, etc.
我需要显示上个月的31、30、29等。
updated code from Renku: 来自Renku的更新代码:
//define the variable dayCol
$dayCol = 0;
// Print last months' days spots.
for ($i=0; $i<$leadInDays; $i++) {
$lastmonth = date('d', strtotime(-$i.' day', strtotime($startDate))); // Days in previous month
print "<td width=\"14%\" height=\"25%\" class=\"calendar_cell_disabled_middle\">$lastmonth</td>\n ";
$dayCol++;
}
example : 例如:
I am writing a new loop for this. 我为此写了一个新循环。
<?php
$StartDate= date("Y-F-d",strtotime("+0 Month"));// get first day of current month
$num= 10; // how many past days you need from previous month + 1 (to remove current day)
for ($i=1; $i<$num; $i++) {
echo $prev= date('Y-m-d', strtotime(-$i.' day', strtotime($StartDate)))."<br />"; //get last days of previous month
}
?>
I am re writing it with your loop, 我用你的循环来写
<?php
$dayCol = 0;
$leadInDays = 5; // (just for February cuz theres 5 blanks before its the 1st of Feb)
$StartDate= date("Y-F-d",strtotime("+0 Month"));
// Print last months' days spots.
for ($i=1; $i<($leadInDays+1); $i++) {
$lastmonth = date('d', strtotime(-$i.' day', strtotime($StartDate))); // Days in previous month
print "<td width=\"14%\" height=\"25%\" class=\"calendar_cell_disabled_middle\">$lastmonth</td>\n ";
$dayCol++;
}
?>
I would use date('t')
to get the number of days in said month and just loop backwards: 我将使用
date('t')
来获取所述月份的天数,然后向后循环:
$month = '2013-02-05';
for($i = date('t', strtotime($month)); $i > 0; $i--) {
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.