act-it.eu/apex/oracle-sql-calculate-amount-of-workdays
Preview meta tags from the act-it.eu website.
Linked Hostnames
6- 14 links toact-it.eu
- 1 link toasktom.oracle.com
- 1 link tocommunity.oracle.com
- 1 link tojekyllrb.com
- 1 link tomademistakes.com
- 1 link totwitter.com
Search Engine Appearance
Oracle SQL: Calculate the amount of workdays (Mon-Fri) between two dates
I searched the net for a problem in finding a way to calculate the workdays between two date values. After I tested a couple of solutions I focused to one where I didn’t necessarily need a extra select to solve that issue. I found a post at asktom.oracle.com The described function itself looked like that: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 -- Created by Sonali Kelkar from Newton, MA USA CREATE OR REPLACE FUNCTION num_business_days(start_date IN DATE, end_date IN DATE) RETURN NUMBER IS busdays NUMBER := 0; stDate DATE; enDate DATE; BEGIN stDate := TRUNC(start_date); enDate := TRUNC(end_date); if enDate >= stDate then -- Get the absolute date range busdays := enDate - stDate -- Now subtract the weekends -- this statement rounds the range to whole weeks (using -- TRUNC and determines the number of days in the range. -- then it divides by 7 to get the number of weeks, and -- multiplies by 2 to get the number of weekend days. - ((TRUNC(enDate,'D')-TRUNC(stDate,'D'))/7)*2 -- Add one to make the range inclusive + 1; /* Adjust for ending date on a saturday */ IF TO_CHAR(enDate,'D') = '7' THEN busdays := busdays - 1; END IF; /* Adjust for starting date on a sunday */ IF TO_CHAR(stDate,'D') = '1' THEN busdays := busdays - 1; END IF; else busdays := 0; END IF; RETURN(busdays); END; / I did had some issues with the TO_CHAR(stDate,'D') logic and my German character set. Because of this I looked further and found a solution by Frank Kulash at the Oracle forum: 1 2 1 + TRUNC (dt) - TRUNC (dt, 'IW') Finally I was able creating a logic which I could use in my select. To make it more readable for you I created a from dual select: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 select (end_date-start_date) - (((TRUNC(end_date,'D')-TRUNC(start_date,'D'))/7)*2) + 1 - case when (1 + TRUNC (end_date) - TRUNC (end_date, 'IW')) = '6' then 1 else 0 end - case when (1 + TRUNC (end_date) - TRUNC (end_date, 'IW')) = '7' then 2 else 0 end + case when (1 + TRUNC (start_date) - TRUNC (start_date, 'IW')) = '7' then 1 else 0 end as amount_of_workdays from ( select to_date('06.03.2015','dd.mm.yyyy') as start_date, to_date('07.03.2015','dd.mm.yyyy') as end_date from dual )
Bing
Oracle SQL: Calculate the amount of workdays (Mon-Fri) between two dates
I searched the net for a problem in finding a way to calculate the workdays between two date values. After I tested a couple of solutions I focused to one where I didn’t necessarily need a extra select to solve that issue. I found a post at asktom.oracle.com The described function itself looked like that: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 -- Created by Sonali Kelkar from Newton, MA USA CREATE OR REPLACE FUNCTION num_business_days(start_date IN DATE, end_date IN DATE) RETURN NUMBER IS busdays NUMBER := 0; stDate DATE; enDate DATE; BEGIN stDate := TRUNC(start_date); enDate := TRUNC(end_date); if enDate >= stDate then -- Get the absolute date range busdays := enDate - stDate -- Now subtract the weekends -- this statement rounds the range to whole weeks (using -- TRUNC and determines the number of days in the range. -- then it divides by 7 to get the number of weeks, and -- multiplies by 2 to get the number of weekend days. - ((TRUNC(enDate,'D')-TRUNC(stDate,'D'))/7)*2 -- Add one to make the range inclusive + 1; /* Adjust for ending date on a saturday */ IF TO_CHAR(enDate,'D') = '7' THEN busdays := busdays - 1; END IF; /* Adjust for starting date on a sunday */ IF TO_CHAR(stDate,'D') = '1' THEN busdays := busdays - 1; END IF; else busdays := 0; END IF; RETURN(busdays); END; / I did had some issues with the TO_CHAR(stDate,'D') logic and my German character set. Because of this I looked further and found a solution by Frank Kulash at the Oracle forum: 1 2 1 + TRUNC (dt) - TRUNC (dt, 'IW') Finally I was able creating a logic which I could use in my select. To make it more readable for you I created a from dual select: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 select (end_date-start_date) - (((TRUNC(end_date,'D')-TRUNC(start_date,'D'))/7)*2) + 1 - case when (1 + TRUNC (end_date) - TRUNC (end_date, 'IW')) = '6' then 1 else 0 end - case when (1 + TRUNC (end_date) - TRUNC (end_date, 'IW')) = '7' then 2 else 0 end + case when (1 + TRUNC (start_date) - TRUNC (start_date, 'IW')) = '7' then 1 else 0 end as amount_of_workdays from ( select to_date('06.03.2015','dd.mm.yyyy') as start_date, to_date('07.03.2015','dd.mm.yyyy') as end_date from dual )
DuckDuckGo
Oracle SQL: Calculate the amount of workdays (Mon-Fri) between two dates
I searched the net for a problem in finding a way to calculate the workdays between two date values. After I tested a couple of solutions I focused to one where I didn’t necessarily need a extra select to solve that issue. I found a post at asktom.oracle.com The described function itself looked like that: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 -- Created by Sonali Kelkar from Newton, MA USA CREATE OR REPLACE FUNCTION num_business_days(start_date IN DATE, end_date IN DATE) RETURN NUMBER IS busdays NUMBER := 0; stDate DATE; enDate DATE; BEGIN stDate := TRUNC(start_date); enDate := TRUNC(end_date); if enDate >= stDate then -- Get the absolute date range busdays := enDate - stDate -- Now subtract the weekends -- this statement rounds the range to whole weeks (using -- TRUNC and determines the number of days in the range. -- then it divides by 7 to get the number of weeks, and -- multiplies by 2 to get the number of weekend days. - ((TRUNC(enDate,'D')-TRUNC(stDate,'D'))/7)*2 -- Add one to make the range inclusive + 1; /* Adjust for ending date on a saturday */ IF TO_CHAR(enDate,'D') = '7' THEN busdays := busdays - 1; END IF; /* Adjust for starting date on a sunday */ IF TO_CHAR(stDate,'D') = '1' THEN busdays := busdays - 1; END IF; else busdays := 0; END IF; RETURN(busdays); END; / I did had some issues with the TO_CHAR(stDate,'D') logic and my German character set. Because of this I looked further and found a solution by Frank Kulash at the Oracle forum: 1 2 1 + TRUNC (dt) - TRUNC (dt, 'IW') Finally I was able creating a logic which I could use in my select. To make it more readable for you I created a from dual select: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 select (end_date-start_date) - (((TRUNC(end_date,'D')-TRUNC(start_date,'D'))/7)*2) + 1 - case when (1 + TRUNC (end_date) - TRUNC (end_date, 'IW')) = '6' then 1 else 0 end - case when (1 + TRUNC (end_date) - TRUNC (end_date, 'IW')) = '7' then 2 else 0 end + case when (1 + TRUNC (start_date) - TRUNC (start_date, 'IW')) = '7' then 1 else 0 end as amount_of_workdays from ( select to_date('06.03.2015','dd.mm.yyyy') as start_date, to_date('07.03.2015','dd.mm.yyyy') as end_date from dual )
General Meta Tags
14- titleOracle SQL: Calculate the amount of workdays (Mon-Fri) between two dates | ACT! IT GmbH
- charsetutf-8
- Content-Security-Policydefault-src 'none'; font-src 'self' data:; script-src 'self' 'unsafe-inline' https://stats.deyama.de; connect-src 'self' https://stats.deyama.de; img-src 'self'; style-src 'self' 'unsafe-inline'; base-uri 'self'; manifest-src 'self'; form-action 'self'; frame-ancestors 'none';
- X-Frame-OptionsDENY
- X-Content-Type-Optionsnosniff
Open Graph Meta Tags
6- og:typearticle
og:locale
de_DE- og:site_nameACT! IT GmbH
- og:titleOracle SQL: Calculate the amount of workdays (Mon-Fri) between two dates
- og:urlhttps://act-it.eu/apex/oracle-sql-calculate-amount-of-workdays/
Item Prop Meta Tags
4- email%74%6F%62%69%61%73%2E%61%72%6E%68%6F%6C%64%40%61%63%74%2D%69%74%2E%65%75
- headlineOracle SQL: Calculate the amount of workdays (Mon-Fri) between two dates
- descriptionI searched the net for a problem in finding a way to calculate the workdays between two date values. After I tested a couple of solutions I focused to one where I didn’t necessarily need a extra select to solve that issue.I found a post at asktom.oracle.comThe described function itself looked like that:1234567891011121314151617181920212223242526272829303132333435363738394041-- Created by Sonali Kelkar from Newton, MA USACREATE OR REPLACE FUNCTION num_business_days(start_date IN DATE, end_date IN DATE) RETURN NUMBER ISbusdays NUMBER := 0;stDate DATE;enDate DATE;BEGINstDate := TRUNC(start_date);enDate := TRUNC(end_date);if enDate >= stDatethen -- Get the absolute date range busdays := enDate - stDate -- Now subtract the weekends -- this statement rounds the range to whole weeks (using -- TRUNC and determines the number of days in the range. -- then it divides by 7 to get the number of weeks, and -- multiplies by 2 to get the number of weekend days. - ((TRUNC(enDate,'D')-TRUNC(stDate,'D'))/7)*2 -- Add one to make the range inclusive + 1; /* Adjust for ending date on a saturday */ IF TO_CHAR(enDate,'D') = '7' THEN busdays := busdays - 1; END IF; /* Adjust for starting date on a sunday */ IF TO_CHAR(stDate,'D') = '1' THEN busdays := busdays - 1; END IF;else busdays := 0;END IF; RETURN(busdays);END;/I did had some issues with the TO_CHAR(stDate,'D') logic and my German character set.Because of this I looked further and found a solution by Frank Kulash at the Oracle forum:121 + TRUNC (dt) - TRUNC (dt, 'IW')Finally I was able creating a logic which I could use in my select. To make it more readable for you I created a from dual select:1234567891011121314select (end_date-start_date) - (((TRUNC(end_date,'D')-TRUNC(start_date,'D'))/7)*2) + 1 - case when (1 + TRUNC (end_date) - TRUNC (end_date, 'IW')) = '6' then 1 else 0 end - case when (1 + TRUNC (end_date) - TRUNC (end_date, 'IW')) = '7' then 2 else 0 end + case when (1 + TRUNC (start_date) - TRUNC (start_date, 'IW')) = '7' then 1 else 0 end as amount_of_workdaysfrom ( select to_date('06.03.2015','dd.mm.yyyy') as start_date, to_date('07.03.2015','dd.mm.yyyy') as end_date from dual )
- datePublished2015-03-13T00:00:00+01:00
Link Tags
11- alternate/feed.xml
- apple-touch-icon/assets/images/apple-touch-icon.png
- canonicalhttps://act-it.eu/apex/oracle-sql-calculate-amount-of-workdays/
- icon/assets/images/favicon-32x32.png
- icon/assets/images/favicon-16x16.png
Emails
1- %74%6F%62%69%61%73%2E%61%72%6E%68%6F%6C%64%40%61%63%74%2D%69%74%2E%65%75
Links
19- https://act-it.eu
- https://act-it.eu/apex/Interactive-grid-after-update-trigger
- https://act-it.eu/apex/apex-anwendung-importen-und-exportieren
- https://act-it.eu/apex/interactive-grid-automatic-position-number
- https://act-it.eu/apex/interactive-grid-validation-check-for-duplicated-column-entries