Avatar of michael el halabi
michael el halabiFlag for France

asked on 

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

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.
ASP

Avatar of undefined
Last Comment
Scott Fell
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of michael el halabi

ASKER

awesome
Avatar of michael el halabi

ASKER

awesome solution, thx expert
Avatar of michael el halabi

ASKER

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 ?
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

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

ASP
ASP

Active Server Pages (ASP) is Microsoft’s first server-side engine for dynamic web pages. ASP’s support of the Component Object Model (COM) enables it to access and use compiled libraries such as DLLs. It has been superseded by ASP.NET, but will be supported by Internet Information Services (IIS) through at least 2022.

82K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo