Page 1 of 1

date() help

Posted: Tue Feb 13, 2007 11:30 am
by pcloadletter
I am looking for a php function that will take in two dates and return an array (or something) with all the valid dates in between. Does anybody know of something that will do this?

Posted: Tue Feb 13, 2007 11:39 am
by RobertGonzalez
Time stamps are measured in seconds. You want an array of numbers incremented by 1?

Posted: Tue Feb 13, 2007 1:47 pm
by feyd
strtotime() is your friend.

Thanks!

Posted: Tue Feb 13, 2007 1:50 pm
by pcloadletter
I just wrote a function on my own...I figured I would try to see if anybody had already done it. here it is...

Code: Select all

function DatesBetween($startDate, $endDate){
	// get the number of days between the two given dates.
	$days = (strtotime($endDate) - strtotime($startDate)) / 86400 + 1;
	$startMonth = date("m", strtotime($startDate));
	$startDay = date("d", strtotime($startDate));
	$startYear = date("Y", strtotime($startDate));	
	$dates;//the array of dates to be passed back
	for($i=0; $i<$days; $i++){
		$dates[$i] = date("n/j/Y", mktime(0, 0, 0, $startMonth , ($startDay+$i), $startYear));
	}
	return $dates;	
}