homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

generating timestamp for date range

 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?




 12:36 pm on Dec 11, 2012 (gmt 0)

Nevermind i've figured it out


 4:03 am on Dec 13, 2012 (gmt 0)

Nice. Care to share how you did it?


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


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved