Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Differenz zwischen zwei Daten ohne Wochenenden

Empfohlene Antworten

Veröffentlicht

Hallo,

Ich möchte in einer Oracle-Datenbank die Tage zwischen zwei Zeitpunkten ermitteln, z.B. 20.01.2010 - 05.01.2010.

Soweit so gut, kein Problem.

Allerdings hätte ich gerne die Tage ohne Wochenenden, also nur die Werktage.

Habt ihr eine Idee, wie ich das hinbekomme?

Danke für eure Unterstützung vorab,

Philipp

Hallo anbei eine eventuelle Möglichkeit im mysql Syntax auf die schnelle.


where .......


and (

date_format (datum, "%d") not 6 or

date_format (datum, "%d") not 7

)



Ich habe jetzt hier keine DB zur Verfügung aber 6 müsste Samstag und 7 und 0 Sonntag sein.

Das date_format müsste es (oder eine ähnliche Funktion) auch unter Oracle geben eventuell syntaktisch anders.

sowas ?


define frdate = '&1'

define todate = '&2'

set verify off

select

'&frdate' From_Date

,'&todate' To_Date,

1 + to_date('&todate') - to_date('&frdate') -

( (TRUNC(to_date('&todate'),'D') - TRUNC(to_date('&frdate'),'D'))/7)*2

+ DECODE(to_char(to_date('&todate'),'D'),7,-1,0)

+ DECODE(to_char(to_date('&frdate'),'D'),1,-1,0) Business_Days

from dual

  • Autor

Ich habe jetzt selbst zwei Lösungen im Netz gefunden:

-- Möglichkeit 1

SELECT count(business_date) business_day

FROM (SELECT TO_DATE ('04.01.2010', 'dd.mm.yyyy')

+ ROWNUM

- 1 business_date

FROM all_objects

WHERE ROWNUM <= TO_DATE ('18.01.2010', 'dd.mm.yyyy') - TO_DATE ('04.01.2010', 'dd.mm.yyyy') + 1)

WHERE TO_CHAR (business_date, 'D') NOT IN ('6', '7');

-- Möglichkeit 2

CREATE OR REPLACE FUNCTION F_BUSINESS_DAYS(V_START_DATE IN DATE, V_END_DATE IN DATE) RETURN NUMBER IS DAY_COUNT NUMBER := 0;

CURR_DATE DATE;

BEGIN -- loop through and update

CURR_DATE := V_START_DATE;

WHILE CURR_DATE <= V_END_DATE

LOOP

--dbms_output.put_line(TO_CHAR(CURR_DATE,'DY'));

--dbms_output.put_line(TO_CHAR(CURR_DATE,'D'));

IF TO_CHAR(CURR_DATE,'D') NOT IN ('6','7') THEN

DAY_COUNT := DAY_COUNT + 1;

END IF;

CURR_DATE := CURR_DATE + 1;

END LOOP;

RETURN DAY_COUNT;

END F_BUSINESS_DAYS;

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.