我想按降序打印过去30天的日期。
Ex:
2015-10-16
2015-10-15
2015-10-14
2015-10-13
2015-10-12
2015-10-11
2015-10-10
2015-10-09
2015-10-08
2015-10-07
2015-10-06
2015-10-05
2015-10-04
2015-10-03
2015-10-02
2015-10-01
2015-09-30
2015-09-29
and so on.....
请注意,它应该是动态的。它应该每天改变.. 我的意思是......最高日期应该是今天的日期..
这是我试过的......
<?php
echo "<select class='input-dropdown2' name='coupon_validity'>";
for($i=1;$i<=30;$i++)
{
$timestring=date('Y-m-d');
$datetime=new DateTime($timestring);
$datetime->modify('-$i day');
$y=$datetime->format('Y-m-d');
echo "<option value='" . $y ."'".">" . $y ."</option>";
}
echo "</select>";
?>
答案 0 :(得分:1)
试试这段代码: -
<?php
for ($i = 0; $i < 30; $i++)
{
$timestamp = time();
$tm = 86400 * $i; // 60 * 60 * 24 = 86400 = 1 day in seconds
$tm = $timestamp - $tm;
echo $the_date = date("Y-m-d", $tm);
echo "<br/>";
}
?>