date() help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pcloadletter
Forum Newbie
Posts: 2
Joined: Tue Feb 13, 2007 11:26 am

date() help

Post 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?
Last edited by pcloadletter on Tue Feb 13, 2007 11:50 am, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Time stamps are measured in seconds. You want an array of numbers incremented by 1?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

strtotime() is your friend.
pcloadletter
Forum Newbie
Posts: 2
Joined: Tue Feb 13, 2007 11:26 am

Thanks!

Post 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;	
}
Post Reply