Calculating the working day in sql sqlitestudio #4406
PatriaMinas
started this conversation in
Show and tell
Replies: 1 comment 2 replies
-
So... do I understand you correctly that you are sharing with everybody a script for Custom SQL Function? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
How to know the working day between a date and time using sql sqlitestudio?
I hope this can help!
Portuguese translation:
"Olá,
Como saber o dia útil entre uma data e o tempo utilizando sql sqlitestudio?
Eu espero que isso possa ajudar!"
The script in text:
CREATE TABLE CALEND(
CLDAY DATE PRIMARY KEY UNIQUE,
NWEEK INT (1) AS (strftime('%w', CLDAY)),
NHOLI INT (1) AS (CASE WHEN strftime('%m-%d', CLDAY) IN ('01-01', '12-25'/more from your country/)
THEN 1 ELSE 0 END),
DWORK INT (1) AS ((CASE WHEN NWEEK IN (0, 6) OR NHOLI = 1 THEN 0 ELSE 1 END)))
;
--Import csv file (calendar.csv) 1900-01-01 to 2099-12-31 example, unique column.
;
--Create sqlitestudio function dweeknd()
SELECT MAX(Q.CLDAY) CLDAY
FROM (
SELECT L.CLDAY
FROM CALEND L
WHERE L.CLDAY >= @Date1 AND L.DWORK = 1 LIMIT (@time2 + 1)) Q
;
SELECT dweeknd('2022-01-01', 365) DAYWORKN
;
calendar.csv
Beta Was this translation helpful? Give feedback.
All reactions