Frage deutsch
~~~~~~~~~~~~~~
Wie ermittle ich den Wochentag?
Question English
~~~~~~~~~~~~~~
Hoiw to configure out the day of the week?
Antwort 1
~~~~~~~~
[ von Thomas Antoni, 10.5.2002 ]
.
Dies ist aufwändiger als man anfangs denkt, da alle Schaltjahre usw.
einberechnet werden müssen. Die Lösung findest Du in im untenstehenden Programm
WeekDay.bas
'**************************************************************************
' WEEKDAY.BAS = Ermittlung des Wochentags So...Fr zu einem bestimmten
Datum
' ===========
' Demo Program for the Week of Day FUNCTION WeekDay%
'
' Demoprogramm fuer die FUNCTION WeeDay%, die den Wochentag
' zu einem vorgegebenen Datum ermittelt
'
' von Thomas Antoni, 27.8.02 - 30.7.05
'***************************************************************************
'
DECLARE FUNCTION WeekDay% (Mon%, Day%, Year%)
'
CLS
INPUT "Gib den Tag ein (1-31): "; Day%
INPUT "Gib den Monat ein (1-12): "; Mon%
INPUT "Gib das Jahr ein (1582-2450): "; Year%
SELECT CASE WeekDay%(Mon%, Day%, Year%)
CASE 0: D$ = "Sonntag"
CASE 1: D$ = "Montag"
CASE 2: D$ = "Dienstag"
CASE 3: D$ = "Mittwoch"
CASE 4: D$ = "Donnaerstag"
CASE 5: D$ = "Freitag"
CASE 6: D$ = "Samstag"
END SELECT
PRINT
PRINT "Der "; Day%; "."; Mon%; "."; Year%; " ist ein "; D$
'
FUNCTION WeekDay% (Mon%, Day%, Year%)
'****************************************************************************
' WeekDay% = Function for Evaluating the Day of the Week
' Funktion zum Ermitteln des Wochtages zu einem vorgegebenen Datum
'
===========================================================================
'
' English Description
' ~~~~~~~~~~~~~~~~~~~~~~
' Function WeekDay% to calculate the day of the week when given the date
in
' integer form: Mon%, Day%, Year% (year: 1582 to 2450)
' Note: Returns (0=Sunday...6=Saturday) or -1 if an error occurs"
'
' Deutsche Beschreibung
' ~~~~~~~~~~~~~~~~~~~~~~
' An die Funktion wird das Jahr (1582...2450), der Monat und der Tag
jeweils
' als Integer-Gr"áen bergeben. Die Funktion liefert 0...6 fr Sonntag
bis
' Samstag zurck bzw. -1 wenn ein Fehler auftritt.
' Die Auswertung des Rckmeldewerts im Hauptprogramm erfolgt normalerweise
in
' einem SELECT CASE Block.
'
' Credits : Dank an Garry Spencer, gspencer*stim.tec.tn.us fuer den aus
' ~~~~~~~~~ Garry's Pogramm WEEKDAY.BAS entnommene Function WEEKDAY "to
' calculate the day of the week when given the date in integer
' form: Mon%, Day%, Year% (year: 1582 to 2450)
' Note: Returns (0=Sunday...6=Saturday) or -1 if an error occurs"
'
' Beispiel 1 : Ausdrucken des Wochentages zum 10.11.99 (war ein
Donnerstag):
' ~~~~~~~~~~ CASE SELECT Weekday%(11, 10, 1999)
' CASE 0: PRINT "Sonntag"
' ...
' CASE 6: PRINT "Samstag"
' END SELECT
'
' Beispiel 2: Den heutigen Wochentag ermitteln:
' ~~~~~~~~~~~ d$ = DATE$
' tag% = VAL(MID$(d$, 4, 2))
' monat% = VAL(LEFT$(d$, 2))
' jahr% = VAL(RIGHT$(d$, 4))
' SELECT CASE WeekDay%(monat%, tag%, jahr%)
' CASE 0: PRINT "Sonntag"
' ...
'
' Credits : Thanks to Garry Spencer (gspencer*stim.tec.tn.us) for giving
me
' ~~~~~~~~~ the idea for this subroutine. The basic functions have been
' derived from Garry's Pogramm WEEKDAY.BAS.
'
' Thomas Antoni, 11.11.99- 27.8.02
' thomas*antonis.de - www.antonis.de -- ww.qbasic.de
'****************************************************************************
DTmp% = 4: Days% = 0: Ofs% = 0: Leap% = 0: WeekDay% = -1
IF Year% < 1582 OR Year% > 2450 OR Mon% < 1 OR Mon% > 12 OR Day%
< 1 THEN EXIT FUNCTION
FOR YTmp% = 1582 TO Year%
DTmp% = (DTmp% + 1 + Leap%) MOD 7
SELECT CASE 0
CASE (YTmp% MOD 400): Leap% = 1
CASE (YTmp% MOD 100): Leap% = 0
CASE (YTmp% MOD 4): Leap% = 1
CASE ELSE: Leap% = 0
END SELECT
NEXT YTmp%
FOR MTmp% = 1 TO Mon%: Ofs% = Ofs% + Days%
SELECT CASE MTmp%
CASE 1: Days% = 31
CASE 2: Days% = 28 + Leap%:
CASE 3: Days% = 31
CASE 4: Days% = 30
CASE 5: Days% = 31
CASE 6: Days% = 30
CASE 7: Days% = 31
CASE 8: Days% = 31
CASE 9: Days% = 30
CASE 10: Days% = 31
CASE 11: Days% = 30
CASE 12: Days% = 31
END SELECT
NEXT MTmp%
IF Day% <= Days% THEN WeekDay% = (DTmp% + Ofs% + Day% - 1) MOD 7
END FUNCTION
Das obige Programm steht im Verzeichnis Progs\ zur Verfügung sowie online
unter www.antonis.de/faq/progs/weekday.bas .
Antwort 2
~~~~~~~~~
[ von TheShadow im QB-Forum, 1.11.2002 ]
.
Es geht deutlich kürzer als der Vorschlag in Antwort 1 - sogar in einer Zeile
Code :-)
wert= ( 1461 * ( jahr + 4800 + ( monat - 14 ) / 12 ) ) / 4 + ( 367 * ( monat
- 2 - 12 * ( ( monat - 14 ) / 12 ) ) ) / 12 - ( 3 * ( ( jahr + 4900 + ( monat -
14 ) / 12 ) / 100 ) ) / 4 + tag - 32075
... dann muss man nur noch Wert MOD 7 nehmen
... und schon hat man Wochentag... jahr=1583 bis 4712
Ich habe übrigens eine sehr umfangreiche Datum-Library gecodet - allerdings
für BlitzBasic.
Diese steht zum Herunterladen bereit unter
www.blitzbase.de/quellcode/datumarithmetik.bb
Answer 3
~~~~~~~~~~~~
[ By Douglas Lusher, 1993 ]
My following program figures out the day of wek for an arbitrary date which
is given in the QBasic DATE$ format MM-DD-YYYY .
Mein folgendes Programm ermittelt den Wochentag zu einem beliebigen
Kalenderdatum, das im Format MM-TT-JJJ vorgegeben wird, also in dem bei QBasic
üblichen Format, welches auch der DATE&-Befehl verwendet.
'*******************************************************************
' WEEKDAY2.BAS = Calulates the day of week for a given date
' ============ Berechnet den Wochentag zu einem beliebigen Datum
'
' (c) DOUGLAS LUSHER, 1993
'******************************************************************
'
DECLARE FUNCTION DOW% (InDate$)
'
CLS
'
SELECT CASE DOW%(DATE$)
CASE 0: D$ = "Saturday / Samstag"
CASE 1: D$ = "Sunday / Sonntag"
CASE 2: D$ = "Monday / Montag"
CASE 3: D$ = "Tuesday / Dienstag"
CASE 4: D$ = "Wednesday / Mittwoch"
CASE 5: D$ = "Thursday / Donnerstag"
CASE 6: D$ = "Friday / Freitag"
END SELECT
'
PRINT "Today is "; D$; " , "; DATE$
SLEEP
END
'
'
FUNCTION DOW% (InDate$)
'returns a value representing the day of the week (0 = Saturday, 1 =
Sunday,
'2 = Monday, etc) for the date string supplied in the form "MM-DD-YYYY"
'
Month% = (ASC(MID$(InDate$, 1)) - 48) * 10
Month% = Month% + (ASC(MID$(InDate$, 2)) - 48)
Day% = (ASC(MID$(InDate$, 4)) - 48) * 10
Day% = Day% + (ASC(MID$(InDate$, 5)) - 48)
Year% = (ASC(MID$(InDate$, 7)) - 48) * 1000
Year% = Year% + (ASC(MID$(InDate$, 8)) - 48) * 100
Year% = Year% + (ASC(MID$(InDate$, 9)) - 48) * 10
Year% = Year% + (ASC(MID$(InDate$, 10)) - 48)
Year% = Year% + (Month% < 3)
Temp& = (Year% * 365&) + (Year% \ 4) - (Year% \ 100) + (Year% \
400)
'
SELECT CASE Month%
CASE 1: Temp& = Temp& + 365
CASE 2: Temp& = Temp& + 396
CASE 3: Temp& = Temp& + 59
CASE 4: Temp& = Temp& + 90
CASE 5: Temp& = Temp& + 120
CASE 6: Temp& = Temp& + 151
CASE 7: Temp& = Temp& + 181
CASE 8: Temp& = Temp& + 212
CASE 9: Temp& = Temp& + 243
CASE 10: Temp& = Temp& + 273
CASE 11: Temp& = Temp& + 304
CASE 12: Temp& = Temp& + 334
END SELECT
'
DOW% = (Temp& + Day%) MOD 7
END FUNCTION
Das obige Programm steht im Verzeichnis Progs\ zur Verfügung sowie online
unter www.antonis.de/faq/progs/weekday2.bas .
Answer 4
~~~~~~~~~~~~~~~~
[ by BOB PERKINS , April 18, 1993 ]
*** Question
Could someone tell me how to call up the name of the day to use in my
programs? (possibly using dos interrupts)
*** Answer
This returns the date and the day of week. Use QuickBASIC with the /L command
line option.
'$INCLUDE: 'qb.bi'
DIM regs AS regtype
regs.ax = &H2A00
interrupt &H21, regs, regs
month% = (regs.dx AND &HFF00) \ 256
day% = regs.dx AND &HFF
year% = regs.cx
dayofweek% = regs.ax AND &HFF
SELECT CASE dayofweek%
CASE 0: day$ = "Sunday"
CASE 1: day$ = "Monday"
CASE 2: day$ = "Tuesday"
CASE 3: day$ = "Wednesday"
CASE 4: day$ = "Thursday"
CASE 5: day$ = "Friday"
CASE 6: day$ = "Saturday"
END SELECT
PRINT day$; SPACE$(2); LTRIM$(STR$(month%)); "-"; LTRIM$(STR$(day%));
PRINT "-"; LTRIM$(STR$(year%))
[ The QBasic-MonsterFAQ --- Start Page: www.antonis.de/faq ]