How to calculate the Businessday and skip the holidays in vbscript
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to calculate the Businessday and skip the holidays in vbscript
I want to calculate the only businessdays, and skip the holidays .For example i want to calculate 3 businessday starting date is 28-11-206 we will skip the today and count tomorrow onwards i.e thursday 01-12-2016 . If any holidays come between the dates we will skip and go to the next day. Could You pelase help me?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you are looking for whether the date falls on weekend then, there is a inbuilt function 'Weekday' in VBScript to check if the date falls on weekend or not.
If you want to verify if the date is a public holiday then you will have to create holiday database or map for lookup. For the most of the applications holiday calendar is stored somewhere you can access that and use it for lookup.
Here is the sample code:
Select Case Weekday(DateToVerify)
Case "7"
Log.Message "Date falls on Saturday.. Continue Test" :VerifyIfDateFallsOnWeekend="SATURDAY"
Case "1"
log.Message "Drade date falls on Sunday.. Continue Test" :VerifyIfDateFallsOnWeekend="SUNDAY"
Case Else
Log.Checkpoint "Date falls on weekdays. Date is : "&DateToVerify :VerifyIfDateFallsOnWeekend="WEEKDAY"
End Select
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Kindly check updated reply for your question:
Here is the sample code:
Select Case Weekday(DateToVerify)
Case "7"
Log.Message "Date falls on Saturday.. Continue Test" :VerifyIfDateFallsOnWeekend="SATURDAY"
Case "1"
log.Message "Drade date falls on Sunday.. Continue Test" :VerifyIfDateFallsOnWeekend="SUNDAY"
Case Else
Log.Checkpoint "Date falls on weekdays. Date is : "&DateToVerify :VerifyIfDateFallsOnWeekend="WEEKDAY"
End Select
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you are looking for whether the date falls on weekend then, there is a inbuilt function called 'Weekday' in VBScript to check if the date falls on weekend or not. If the date falls on weekend or on a holiday then use DateAdd Function as specified below.
Here is the sample code:
Select Case Weekday(DateToVerify)
Case "7"
Log.Message "Date falls on Saturday.. Continue Test" :VerifyIfDateFallsOnWeekend="SATURDAY"
Case "1"
log.Message "Drade date falls on Sunday.. Continue Test" :VerifyIfDateFallsOnWeekend="SUNDAY"
Case Else
Log.Checkpoint "Date falls on weekdays. Date is :&DateToVerify :VerifyIfDateFallsOnWeekend="WEEKDAY"
End Select
DateAdd Function:
If (IsWeekday = "SATURDAY") then
Date = DateAdd("d",2,NextDate)
If you want to verify if the date is a public holiday, then you will have to create holiday database or map to lookup, since public holidays varies from country to country every year, you should use App holiday data for your date processing.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Could You please write the function properly i am not understanding dnyaneshmohite. I have to check the saturday ,sunday and holidays list.The Holiday list as follws("January 01","January 15","January 26","April 17","May 21","July 17","August 15","September 05","October 02","October 11","October 21","November 10")
Please wrtite the function as per above requirement
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"Please wrtite the function as per above requirement"
lolwut?!?!
Sorry to be blunt here ..... but you've been given several answers. TC provides plenty built in date functions so you can easily do the Saturday/Sunday part. All you need to do on top of that is check against a list of dates (which you've provided).
ie. Everything is there to put this together yourself. And it doesn't strike me a very complex task. But you want some random forum poster to write it for you???
Sorry to say it ...... but if you want to learn, and improve, you would be far better doing this yourself! (It's also your job!!!)
