Jump to content

List dates between two dates


Eiolon

Recommended Posts

I can find the number of days between two dates, however, I want the actual dates listed instead.  Any examples on how to do this?

 

Let's say I want to fnd the dates between 2007-12-01 and 2007-12-05.  The output would be:

 

2007-12-01

2007-12-02

2007-12-03

2007-12-04

2007-12-05

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/80029-list-dates-between-two-dates/
Share on other sites

The strtotime() and date() functions are your friends here:

 

<?php
function listdates($startdate,$enddate,$format='Y-m-d'){
$date = strtotime($startdate);//convert to unix timestamp
$enddate = strtotime($enddate);
while($date <= $enddate){
	echo date($format,$date)."<br /> \n";
	$date += 60*60*24;
}
}
listdates('2007-12-01','2007-12-05')
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.