i want to print all date from today to specific day this specific day will be taken from database
$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'];
this code give me number of date example 10 days i want to print date from today to 13 days
for($i=1;$i<=$day;$i++){
}
output will be like this
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
try my edited code.
$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)."
";
$start_day = $start_day + 86400;
}
I hope its helps
<?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)));
}
You could use the Datetime
class and it's associated methods
/* 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 />';
}
Will output:
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