Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB Script DateAdd Function to exclude Holidays and Sundays

Posted on 2009-07-14
3
Medium Priority
?
1,151 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

722 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