Solved

VB Script DateAdd Function to exclude Holidays and Sundays

Posted on 2009-07-14
3
1,071 Views
Last Modified: 2012-05-07
I have a vbscript that adds 4 days to a Status date from our database. I need to exclude holidays and sundays from the dateadd function.

For example if the status date is today (7/14/2009) and add 4 days, it would be Saturday (7/18/2009).
If the status date is tomorrow (7/15/2009) and add 4 days, it would need to exclude Sunday and result = 7/20/2009
If the status date is 7/1/2009 and add 4 days, it would need to exclude Saturday ( 4th of July Holiday) and Sunday and result = 7/7/2009

Any ideas how to do this? Thanks.
dim nowdate
 
nowdate = datevalue(Status_Date_INLQ("Redisclosed to Borrower"))
 
Result = dateadd("d",4,nowdate)

Open in new window

0
Comment
Question by:asmyatt
  • 2
3 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 24854777
Hi, asmyatt.

What do you want the script to do if the date does fall on a holiday or Sunday?
0
 
LVL 2

Author Comment

by:asmyatt
ID: 24858960
If the result date falls on a holiday or Sunday, it need to add another day. It does not need to fall on a holiday or Sunday.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 24859718
Ok.  You need something like the code below.  You'll have to write the IsHoldiay function.  I'm not sure how you're going to determine if a day is a holiday and if it's one you want to skip over (I assume you might not want to skip over things like Take Your Boss to Lunch Day).  
dim nowdate
 
nowdate = datevalue(Status_Date_INLQ("Redisclosed to Borrower"))
 
Result = dateadd("d",4,nowdate)
 
Do Until (WeekDay(Result) <> vbSunday) And (Not IsHoliday(Result))
    Result = DateAdd("d",1,Result)
Loop

Open in new window

0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question