date() help
Moderator: General Moderators
-
pcloadletter
- Forum Newbie
- Posts: 2
- Joined: Tue Feb 13, 2007 11:26 am
date() help
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.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
strtotime() is your friend.
-
pcloadletter
- Forum Newbie
- Posts: 2
- Joined: Tue Feb 13, 2007 11:26 am
Thanks!
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;
}