Activer Server Pages create a loop to generate dates, hour and minutes

michael el halabi
michael el halabi used Ask the Experts™
on
Hi Experts

I want to generate dates from to day to next year the same day, ie:
13/11/2017 18:57:29
14/11/2017 18:57:29
15/11/2017 18:57:29
16/11/2017 18:57:29
etc...

But I want to exclude Fridays and Saturdays

And I want to divide each day by 11 hours starting from 8 AM to 7PM,  and each hour divided by 15 minutes

Ie:
13/11/2017 08:00:00
13/11/2017 08:15:00
13/11/2017 08:30:00
13/11/2017 08:45:00
13/11/2017 09:00:00
13/11/2017 09:15:00
13/11/2017 09:30:00
etc... until
13/11/2017 : 19:00:00

And then display next day, and so on

Can anyone please help me with the code.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
startDate = "11/9/2019 8:00:00 AM"
endDate = dateAdd("y",1,startDate)
currentDate = startDate

Do Until currentDate = endDAte

  response.write currentDate &"<br>"
  currentDate=dateAdd("n",15,currentDate

Loop

Open in new window


See dateAdd https://www.w3schools.com/asp/func_dateadd.asp
Developer & EE Moderator
Fellow 2018
Most Valuable Expert 2013
Commented:
This is the one that should do the trick including excluding Fri and Sat

<%
startDate = "11/9/2017 8:00:00 AM"
endDate = dateAdd("yyyy",1,startDate)
currentDate = startDate

   
Do until cdate(currentDate) > cdate(endDate)

  if Weekday(currentDate) <> 6 and Weekday(currentDate) <> 7 then
  response.write FormatDateTime(currentDate,1)&" "&FormatDateTime(currentDate,3)   &" | Weekday Number: " & Weekday(currentDate) & " | Weekday Name:"& weekdayname(Weekday(currentDate)) &"<br>"
  response.flush	
  end if
  currentDate=dateAdd("n",15,currentDate)
  
   
Loop
   
%>

Open in new window

Output
Thursday, November 9, 2017 8:00:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 8:15:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 8:30:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 8:45:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 9:00:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 9:15:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 9:30:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 9:45:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 10:00:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 10:15:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 10:30:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 10:45:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 11:00:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 11:15:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 11:30:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 11:45:00 AM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 12:00:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 12:15:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 12:30:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 12:45:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 1:00:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 1:15:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 1:30:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 1:45:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 2:00:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 2:15:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 2:30:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 2:45:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 3:00:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 3:15:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 3:30:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 3:45:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 4:00:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 4:15:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 4:30:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 4:45:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 5:00:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 5:15:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 5:30:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 5:45:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 6:00:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 6:15:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 6:30:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 6:45:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 7:00:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 7:15:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 7:30:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 7:45:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 8:00:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 8:15:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 8:30:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 8:45:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 9:00:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 9:15:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 9:30:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 9:45:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 10:00:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 10:15:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 10:30:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 10:45:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 11:00:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 11:15:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 11:30:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Thursday, November 9, 2017 11:45:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Sunday, November 12, 2017 12:00:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 12:15:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 12:30:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 12:45:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 1:00:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 1:15:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 1:30:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 1:45:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 2:00:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 2:15:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 2:30:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 2:45:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 3:00:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 3:15:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 3:30:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 3:45:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 4:00:00 AM | Weekday Number: 1 | Weekday Name:Sunday
Sunday, November 12, 2017 4:15:00 AM | Weekday Number: 1 | Weekday Name:Sunday

Open in new window

Author

Commented:
awesome
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Author

Commented:
awesome solution, thx expert

Author

Commented:
just a little problem

Each day time must start at 8:00 AM and  stops at 07:PM

Your code does start at 8:00 am but never ends

ie :
Thursday, November 09, 2017 11:45:00 PM | Weekday Number: 5 | Weekday Name:Thursday
Sunday, November 12, 2017 12:00:00 AM | Weekday Number: 1 | Weekday Name:Sunday

Thursday must start at 8:00 AM and ends at 07:00 PM
Sunday  must start at 8:00 AM and ends at 07:00 PM

Do you please have a fix ?
Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
startDate = "11/9/2017 8:00:00 AM"
endDate = dateAdd("yyyy",1,startDate)
currentDate = startDate

   
Do until cdate(currentDate) > cdate(endDate)

  if Weekday(currentDate) <> 6 and Weekday(currentDate) <> 7 then
	if hour(currentDate)>=8 AND (hour(currentDate)< 19 OR formatDateTime(currentDate,4) = "19:00")  then
        response.write FormatDateTime(currentDate,1)&" "&FormatDateTime(currentDate,3)   &" | Weekday Number: " & Weekday(currentDate) & " | Weekday Name:"& weekdayname(Weekday(currentDate)) &"<br>"
  response.flush
	end if						  
  end if
  currentDate=dateAdd("n",15,currentDate)
  
   
Loop

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial