[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
Solved

# DateAdd (with minutes) to skip weekends in classic ASP

Posted on 2012-03-30
Medium Priority
865 Views
I'm doing some development in classic ASP.  I have a starting datetime value and I want to add to it a period of time in minutes, but it needs to skip weekends.

For example, if I have a starting datetime of Thursday @ 7:00am and I add to it 3045 minutes (50 hours: 45 minutes)...it should finish on Monday @ 9:45am.

Any ideas?

Thanks.
bruno71
0
Question by:bruno71
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 54

Accepted Solution

Scott Fell,  EE MVE earned 2000 total points
ID: 37788556
I'm sure there is more then one way to do this.  I would start with finding the end date, then looping through each day to find which is a weekend day, then add the minutes for those days.  If you need to account for the start date being a weekend, then find the time it starts and subtract those minutes.  I have not tested this.

``````'Assumes your start date is not on a weekend.
StartDate=request("StartDate") 'format should be in something like, "1/1/2012 08:50:00"
totDays=datediff("d",StartDate,EndDate) ' find out how many days you are adding.

WeekEndCounter =0
for x = 1 to totDays
if Weekday(DateAdd("d",x,StartDate) )=1 or Weekday(DateAdd("d",x,StartDate) )=7 then ' check for sunday or saturday
WeekEndCounter=WeekEndCounter+1
next
AddMoreMinutes=WeekEndCounter*1440 ' 1440 minutes in a day ' could have just done days too for this

' If you need to account for the start date being a weekend, then we need to subtract some minutes.
If weekday(StartDate) = 1 or weekday(StartDate) = 7 then
SubtractMinutes = ((hour(DateStart)*60 ) + minute(DateStart)) * -1

end if
``````
0

Author Closing Comment

ID: 37797422

This is to account for the recalculated ending date being on a weekend...

Do While Weekday(EndDate) = 1 or Weekday(EndDate) = 7
Loop

For example, if the ending date landed on a Tuesday and we skipped two weekends...the calculation would add 4 days - landing on a Saturday.  This just loops through to the next weekday.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Introduction to Processes
###### Suggested Courses
Course of the Month12 days, 23 hours left to enroll