| generating timestamp for date range
|
ahmed24

msg:4526597 | 1:48 pm on Dec 10, 2012 (gmt 0) | I have a date range stored as variables $start and $end i need to generate timestamps for every single weekday that falls in between those two dates with a time of 08:00 every single weekday and then echo those dates. any ideas how i can achieve this? thanks
|
ahmed24

msg:4526931 | 12:36 pm on Dec 11, 2012 (gmt 0) | Nevermind i've figured it out
|
coopster

msg:4527642 | 4:03 am on Dec 13, 2012 (gmt 0) | Nice. Care to share how you did it?
|
ahmed24

msg:4529606 | 11:05 am on Dec 19, 2012 (gmt 0) | I defined the $start and $end values, then calculated all the dates available between these two dates. Then if each individual date is monday-friday added it to an array called $timestampArray. All the possible weekdays that fall between the two date ranges are stored in this array as a timestamp. I can then loop through each date and use it for my script. Heres the code:
$start = "02-DEC-2012"; $end = "13-FEB-2013";
for ($currentDate = strtotime($start); $currentDate <= strtotime($end); $currentDate += (60 * 60 * 24)) {
$day = strtolower(gmdate('D',$currentDate)); $daynumber = gmdate('d',$currentDate); $month = gmdate('m',$currentDate); $year = gmdate('Y',$currentDate);
if($day=='mon' || $day=='tue' || $day=='wed' || $day=='thu' || $day=='fri') { $timestampArray[] = mktime ("8", "00", "00", $month, $daynumber, $year); }
}
|
|
|