Debug.Print DateAdd("D", 15, myDate)
return 20/02/2020
but i need to calculate only a working day, without all holyday days
HOW to add 15 working day to 05/02/2020...
-
- PlatinumLounger
- Posts: 4364
- Joined: 26 Apr 2010, 17:36
-
- Administrator
- Posts: 78572
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: HOW to add 15 working day to 05/02/2020...
Excel has a WORKDAY function, but I assume that you want to do this in VB6.
Do you have an array with public holidays, or a holidays table in a database, or …?
Do you have an array with public holidays, or a holidays table in a database, or …?
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4364
- Joined: 26 Apr 2010, 17:36
Re: HOW to add 15 working day to 05/02/2020...
In this time i need only to add days without SABATO and DOMENICAHansV wrote:Excel has a WORKDAY function, but I assume that you want to do this in VB6.
Do you have an array with public holidays, or a holidays table in a database, or …?
-
- Administrator
- Posts: 78572
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: HOW to add 15 working day to 05/02/2020...
Here is a function:
Example of use:
Code: Select all
Function Workday(StartDate As Date, Days As Long) As Date
Dim N As Long
Dim C As Long
Dim I As Long
Dim D As Long
I = Sgn(Days)
D = Abs(Days)
Do Until C = D
N = N + I
If Weekday(StartDate + N, vbMonday) < 6 Then
C = C + 1
End If
Loop
Workday = StartDate + N
End Function
Code: Select all
Debug.Print Workday(MyDate, 15)
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4364
- Joined: 26 Apr 2010, 17:36
Re: HOW to add 15 working day to 05/02/2020...
WORK Bro!HansV wrote:Here is a function:
Example of use:Code: Select all
Function Workday(StartDate As Date, Days As Long) As Date Dim N As Long Dim C As Long Dim I As Long Dim D As Long I = Sgn(Days) D = Abs(Days) Do Until C = D N = N + I If Weekday(StartDate + N, vbMonday) < 6 Then C = C + 1 End If Loop Workday = StartDate + N End Function
Code: Select all
Debug.Print Workday(MyDate, 15)
But possibe, during this loop, how to debug.print the list of days in this format DD/MM/YYYY?
example:
N=15
05/02/2020
06/02/2020
07/02/2020
10/02/2020
11/02/2020
...
24/02/2020
-
- Administrator
- Posts: 78572
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: HOW to add 15 working day to 05/02/2020...
Code: Select all
Function Workday(StartDate As Date, Days As Long) As Date
Dim N As Long
Dim C As Long
Dim I As Long
Dim D As Long
I = Sgn(Days)
D = Abs(Days)
Do Until C = D
N = N + I
If Weekday(StartDate + N, vbMonday) < 6 Then
Debug.Print Format(StartDate + N, "dd/mm/yyyy")
C = C + 1
End If
Loop
Workday = StartDate + N
End Function
Best wishes,
Hans
Hans