Welcome to WebmasterWorld Guest from 50.16.112.199

Forum Moderators: coopster & jatar k

generating timestamp for date range

   
1:48 pm on Dec 10, 2012 (gmt 0)

5+ Year Member



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
12:36 pm on Dec 11, 2012 (gmt 0)

5+ Year Member



Nevermind i've figured it out
4:03 am on Dec 13, 2012 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Nice. Care to share how you did it?
11:05 am on Dec 19, 2012 (gmt 0)

5+ Year Member



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);
}


}


 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month