Solved

VB Script DateAdd Function to exclude Holidays and Sundays

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 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