Solved

VB Script DateAdd Function to exclude Holidays and Sundays

Posted on 2009-07-14
3
1,041 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now