Solved

VB Script DateAdd Function to exclude Holidays and Sundays

Posted on 2009-07-14
3
1,122 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
[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
  • Learn & ask questions
  • 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

624 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