Php 显示上个月的最后几天

Php 显示上个月的最后几天,php,mysql,Php,Mysql,我搜索了数百万类似的帖子,但找不到如何从31、30、29、28等倒计时 我可以让之前的日历块显示31号,但仅此而已。我需要它显示上个月的31号,30号,29号等等 Renku更新的代码: //define the variable dayCol $dayCol = 0; // Print last months' days spots. for ($i=0; $i<$leadInDays; $i++) { $lastmonth = date('d

我搜索了数百万类似的帖子,但找不到如何从31、30、29、28等倒计时

我可以让之前的日历块显示31号,但仅此而已。我需要它显示上个月的31号,30号,29号等等

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++;
}
示例:

我将使用date't'获取所述月份的天数,然后向后循环:

$month = '2013-02-05';

for($i = date('t', strtotime($month)); $i > 0; $i--) {
  ...
}

我正在为此编写一个新的循环

 <?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

}

    ?>
我正在用你的循环重新写它

<?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++;
}
?>

测试它

从for$i=$leadInDays开始$i> 0$我-{也许?当我使用你的$lastmount=date'd',strotime-$i.'day',strotime$startDate;它倒计时31-30-29-28-27-1-2-3-4$leadInDays=5;//就在二月,因为在它的第一个Febi运行你提供的测试链接之前有5个空格,结果是:31-30-29-27我希望它是正确的……它是二月,还有o输出是1月31日至27日。您不需要吗?我的$startDate=mktime0,0,0,$month,1,$year;