如何打印一个月或更长时间的所有日期


how to print all date for a month or more

我想打印从今天到特定日期的所有日期,该特定日期将从数据库中获取

$sql=mysqli_query($conn,"select * from tbl_activities where db_id='$id'")or die(mysqli_error($conn));
$row=mysqli_fetch_array($sql);
$day=$row['db_day'];

这段代码给了我10天的日期示例我想打印从今天到13天的

for($i=1;$i<=$day;$i++){
}

输出将像这个

Thursday 21st of July 2016
Friday 22st of July 2016
       23st of July 2016
       24st of July 2016
       25st of July 2016
       26st of July 2016
       27st of July 2016
       28st of July 2016
       29st of July 2016
       30st of July 2016
       31st of July 2016
       1st of August 2016

试试我编辑过的代码。

$day=$row['db_day'];
$start_day = strtotime(date("Y-m-d"));
$end_day = $start_day + 86400 * $day;
    while($end_day >= $start_day){
            echo date("j F, Y",$start_day)."'r'n";
            $start_day = $start_day + 86400;
    }

我希望它能帮助

<?php
$date = date('Y-m-d');
$end_date = date('Y-m-d', strtotime('+9 days')); //add the num of days u need here
while (strtotime($date) <= strtotime($end_date)) {
       echo "<pre>".$date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
 }

您可以使用Datetime类及其关联的方法

/* formats for dates */
$df='Y-m-d H:i:s';
$dfo='l jS 'of F, Y';
/* variable, number of days from NOW */
$days=14;
/* set the timezone and date interval */
$timezone=new DateTimeZone('Europe/London');
$interval=new DateInterval('P1D');
/*establish date range */
$ts=date( $df, strtotime('yesterday') );
$tf=date( $df, strtotime('1st August 2016') );
/* Alternatively... */
$tf=date( $df, strtotime('now +'.$days.' days') );

/* create instances of the `Datetime` class for both dates */
$start=new DateTime( $ts, $timezone );
$end=new DateTime( $tf, $timezone );
/* show the dates in the range */
while( $start->add( $interval ) <= $end ){
    echo $start->format( $dfo ). '<br />';
}

将输出:

Thursday 21st of July, 2016
Friday 22nd of July, 2016
Saturday 23rd of July, 2016
Sunday 24th of July, 2016
Monday 25th of July, 2016
Tuesday 26th of July, 2016
Wednesday 27th of July, 2016
Thursday 28th of July, 2016
Friday 29th of July, 2016
Saturday 30th of July, 2016
Sunday 31st of July, 2016
Monday 1st of August, 2016
Tuesday 2nd of August, 2016
Wednesday 3rd of August, 2016
Thursday 4th of August, 2016