Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Networkdays with saturday

Hello,

I have to count how many working days there are between two dates, but I have to consider that Saturday is ALWAYS a working day, so I cant's use the networkingdays() function, which excludes Saturday. At the same time, I can't use a calendar because I have to use the calculation for many occurrences in various years, so it should be too difficult for me to load a so long calendars.

Can anyone suggest an idea to me?

Thank you for interesting.

1 Solution

Accepted Solutions
Gysbert_Wassenaar

Ah, ehm, you can't. Not without using a calendar, which you don't want to do. You could try adding a vbscript function in the macro editor:

Function GetWorkDays(StartDate, EndDate)

    dCount = 0

    For dt = StartDate To EndDate

        If WeekDay(dt) <> 1 Then

            dCount = dCount + 1

        End If

    Next

    GetWorkDays = dCount

End Function

And use that function in the load script. Make sure the dates that are passed to the function are numeric dates.

GetWorkDays(StartDate,EndDate) as WorkingDays


talk is cheap, supply exceeds demand

View solution in original post

15 Replies
Gysbert_Wassenaar

You could add a new field in the script: if(weekday(MyDate)<>6,1,0) as WorkDay. You can then sum the workday field to get the number of workdays. If you don't want to create a new field you can use the if statement in an expression in your chart.


talk is cheap, supply exceeds demand
Anonymous
Not applicable
Author

Sorry but I didn't understand.

This is the part of my script when I apply the function:

LOAD

    Date(StartDate,'DD/MM/YY') As StartDateFormatted,

    Date(EndDate,'DD/MM/YY') As EndDateFormatted,

    networkdays (DataInizio, DataFine) As WorkingDays;

SQL SELECT

    IdPersona,

    StartDate,

    EndDate,

FROM Table;

How can I apply your suggestion?

Thanks

Gysbert_Wassenaar

Ah, ehm, you can't. Not without using a calendar, which you don't want to do. You could try adding a vbscript function in the macro editor:

Function GetWorkDays(StartDate, EndDate)

    dCount = 0

    For dt = StartDate To EndDate

        If WeekDay(dt) <> 1 Then

            dCount = dCount + 1

        End If

    Next

    GetWorkDays = dCount

End Function

And use that function in the load script. Make sure the dates that are passed to the function are numeric dates.

GetWorkDays(StartDate,EndDate) as WorkingDays


talk is cheap, supply exceeds demand
Anonymous
Not applicable
Author

Great!!

Thank you very much.

N.

rbecher
MVP
MVP

Hi N.

since there is no function for script (except Marco) I would prefer a calculation in script:

Load

floor(((Date2 - Date1)+1)/7)*6 + mod((Date2 - Date1)+1,7)

+ if(Weekday(Date1) + mod((Date2 - Date1)+1,7) < 6, 0, -1) as Workingdays_6

...

Please see atached example. Hope I have covered all variations. Maybe there is a possibility of simplification ..

- Ralf

Astrato.io Head of R&D
Anonymous
Not applicable
Author

Hello,

Thank you for your solution, but it dosn't work properly:

12/12/12 - 22/12/12 Working days: 10 Your function: 9

17/12/12 - 22/12/12 Working days: 6 Your function: 5

20/12/12 - 22/12/12 Working days: 3 Your function: 2

Have a nice WE.

N.

rbecher
MVP
MVP

Small mistake..

Load

floor(((Date2 - Date1)+1)/7)*6 + mod((Date2 - Date1)+1,7)

+ if(Weekday(Date1) + mod((Date2 - Date1)+1,7) < 7, 0, -1) as Workingdays_6

...

Have a good one!

- Ralf

Astrato.io Head of R&D
Anonymous
Not applicable
Author

Yeah !!

My best compliments for your ability with math! You're a sort of genius with the numbers...

Thank to both of you.

N.

rbecher
MVP
MVP

Thx, this is just basic stuff. I'm not that math geek 😉

But a good exercise...

Astrato.io Head of R&D