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

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
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Developer & EE ModeratorCommented:
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
``````

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented: