WEEKDAY PowerBASIC Function |
WEEKDAY$ function evaluates to abbreviated name of the day of a week (Sun, Mon, Tue, Wed, Thu, Fri, Sat) for the date specified as its parameter. Date should be specified in one of the formats MM-DD-YY or MM-DD-CCYY and should be a valid date in Gregorian calendar. If parameter doesn't represent a valid date, "***" is returned instead of day of a week value. If century is omitted, the current century is assumed. Date field delimiters are expected to be in the fixed positions 3 and 5; values of delimiters are insignificant. If parameter is empty, day of a week value is returned for the current date. Direct dependency:
Indirect dependencies:
WEEKDAY$ Source Program Debugging program Debugging logout |
' WEEKDAY$(3.0) Form Day of a Week Abbreviated Name 09/30/1992-02/03/2010 ' ------------------------------------------------------------------------------ ' Copyright (C) 1992-2010 by Vladimir Veytsel www.davar.net ' Type ------------------------------------------------------------------------- ' Function ' Description ------------------------------------------------------------------ ' WEEKDAY$ function returns the name of the day of a week (abbreviated ' to three characters) for the specified date. ' Parameter -------------------------------------------------------------------- ' Spec_Date$ - Specified date in the form of MM-DD-YY or MM-DD-CCYY ' (should be a valid date in Gregorian calendar) ' Value ------------------------------------------------------------------------ ' Three character day of the week identification for the specified date. ' Notes ------------------------------------------------------------------------ ' - Delimiters of parameter date fields are irrelevant and can be any ' symbols. Date fields are extracted from fixed positions. ' - IF century part is not specified (total year length is 2 characters), ' THEN CURRENT century is assumed (two digit of century get appended ' before YY). ' - If specified date is EMPTY, ' then day of a week identification is returned for the CURRENT date. ' - IF specified date doesn't represent a proper Gregorian calendar date, ' THEN "***" is returned instead of day of a week identification ' as an eye-catcher for an error in date specification. ' - Day of a week is determined by the formula that was derived from the ' algorithm suggested by Christian Zeller in 1883 (Zeller's Congruence). ' D - Day within specified month ' M - Month within specified year ' Y - Year (full 4-digit including century) ' If (M<3) ' M=M+12 ' Y=Y-1 ' WDI=(D+INT((13*M-27)/5)+Y+INT(Y/4)-INT(Y/100)+INT(Y/400)) MOD 7 ' WDI - Week Day Index for the given date (0-Sun, 1-Mon, ..., 6-Sat) ' - Formula works for dates after 09/14/1752 - when England and its ' colonies switched from Julian calendar to currently used Gregorian. ' Examples --------------------------------------------------------------------- ' WEEKDAY$("" )="Fri" - Today 03-08-2002 ' WEEKDAY$("*1-01-1996")="***" ' WEEKDAY$("12-31-1996")="Tue" ' WEEKDAY$("01-01-1997")="Wed" ' WEEKDAY$("12-31-1997")="Wed" ' WEEKDAY$("01-01-1998")="Thu" ' WEEKDAY$("12-31-1998")="Thu" ' WEEKDAY$("01-01-1999")="Fri" ' WEEKDAY$("12-31-1999")="Fri" ' WEEKDAY$("01-01-2000")="Sat" ' WEEKDAY$("12-31-2000")="Sun" ' WEEKDAY$("01-01-2001")="Mon" ' WEEKDAY$("12-31-2001")="Mon" ' WEEKDAY$("01-01-2002")="Tue" ' WEEKDAY$("12-31-2002")="Tue" ' WEEKDAY$("01-01-2003")="Wed" ' WEEKDAY$("12-31-2003")="Wed" ' WEEKDAY$("01-01-2004")="Thu" ' WEEKDAY$("12-31-04" )="Fri" ' External Function ------------------------------------------------------------ #INCLUDE ONCE "VALDGRE" ' Start Function --------------------------------------------------------------- DEFINT A-Z ' All defaulted variables are integer FUNCTION WEEKDAY$(Spec_Date$) ' Check Date Validity and Handle Default Empty Date (Current) ------------------ IF (LEN(Spec_Date$)=0) THEN DT$=DATE$ ELSEIF (VALDGRE%(Spec_Date$)) THEN DT$=Spec_Date$ ELSE WEEKDAY$="***" EXIT FUNCTION END IF ' Form Date Working Variables -------------------------------------------------- Month=VAL(LEFT$(DT$,2)) Day =VAL( MID$(DT$,4,2)) IF (LEN(DT$)=8) THEN Year=VAL(MID$(DATE$,7,2)+RIGHT$(DT$,2)) ' Use current century ELSE Year=VAL(RIGHT$(DT$,4)) END IF ' Form and Return Day of a Week Value to the Point of Invocation --------------- IF (Month<3) THEN Month=Month+12 Year=Year-1 END IF Day_Index=(Day+INT((13*Month-27)/5)+Year+INT(Year/4)-INT(Year/100)+ _ INT(Year/400)) MOD 7 WEEKDAY$=MID$("SunMonTueWedThuFriSat",3*Day_Index+1,3) ' Finish Function -------------------------------------------------------------- END FUNCTION
WEEKDAY$ Debugging Program Source program Debugging logout |
' WEEKDAY$(3.0) Form Day of a Week Abbreviated Name 09/30/1992-02/03/2010 ' ------------------------------------------------------------------------------ #INCLUDE "WEEKDAY" FUNCTION PBMAIN PRINT "WEEKDAY$(3.0) Form Day of a Week Abbreviated Name ";DATE$; PRINT " ";LEFT$(TIME$, 5) PRINT STRING$(69,"-") PRINT PRINT "WEEKDAY$('' )='"; WEEKDAY$(""); "' - Today "; DATE$ PRINT "WEEKDAY$('*1-01-1996')='"; _ WEEKDAY$("*1-01-1996"); "' - Should be '***' (error)" PRINT "WEEKDAY$('12-31-1996')='"; _ WEEKDAY$("12-31-1996"); "' - Should be 'Tue'" PRINT "WEEKDAY$('01-01-1997')='"; _ WEEKDAY$("01-01-1997"); "' - Should be 'Wed'" PRINT "WEEKDAY$('12-31-1997')='"; _ WEEKDAY$("12-31-1997"); "' - Should be 'Wed'" PRINT "WEEKDAY$('01-01-1998')='"; _ WEEKDAY$("01-01-1998"); "' - Should be 'Thu'" PRINT "WEEKDAY$('12-31-1998')='"; _ WEEKDAY$("12-31-1998"); "' - Should be 'Thu'" PRINT "WEEKDAY$('01-01-1999')='"; _ WEEKDAY$("01-01-1999"); "' - Should be 'Fri'" PRINT "WEEKDAY$('12-31-1999')='"; _ WEEKDAY$("12-31-1999"); "' - Should be 'Fri'" PRINT "WEEKDAY$('01-01-2000')='"; _ WEEKDAY$("01-01-2000"); "' - Should be 'Sat'" PRINT "WEEKDAY$('12-31-2000')='"; _ WEEKDAY$("12-31-2000"); "' - Should be 'Sun'" PRINT "WEEKDAY$('01-01-2001')='"; _ WEEKDAY$("01-01-2001"); "' - Should be 'Mon'" PRINT "WEEKDAY$('12-31-2001')='"; _ WEEKDAY$("12-31-2001"); "' - Should be 'Mon'" PRINT "WEEKDAY$('01-01-2002')='"; _ WEEKDAY$("01-01-2002"); "' - Should be 'Tue'" PRINT "WEEKDAY$('12-31-2002')='"; _ WEEKDAY$("12-31-2002"); "' - Should be 'Tue'" PRINT "WEEKDAY$('01-01-2003')='"; _ WEEKDAY$("01-01-2003"); "' - Should be 'Wed'" PRINT "WEEKDAY$('12-31-2003')='"; _ WEEKDAY$("12-31-2003"); "' - Should be 'Wed'" PRINT "WEEKDAY$('01-01-2004')='"; _ WEEKDAY$("01-01-2004"); "' - Should be 'Thu'" PRINT "WEEKDAY$('12-31-04' )='"; _ WEEKDAY$("12-31-04" ); "' - Should be 'Fri'" END FUNCTION
WEEKDAY$ Debugging Logout Source program Debugging program |
WEEKDAY$(3.0) Form Day of a Week Abbreviated Name 09-17-2016 18:57 --------------------------------------------------------------------- WEEKDAY$('' )='Sat' - Today 09-17-2016 WEEKDAY$('*1-01-1996')='***' - Should be '***' (error) WEEKDAY$('12-31-1996')='Tue' - Should be 'Tue' WEEKDAY$('01-01-1997')='Wed' - Should be 'Wed' WEEKDAY$('12-31-1997')='Wed' - Should be 'Wed' WEEKDAY$('01-01-1998')='Thu' - Should be 'Thu' WEEKDAY$('12-31-1998')='Thu' - Should be 'Thu' WEEKDAY$('01-01-1999')='Fri' - Should be 'Fri' WEEKDAY$('12-31-1999')='Fri' - Should be 'Fri' WEEKDAY$('01-01-2000')='Sat' - Should be 'Sat' WEEKDAY$('12-31-2000')='Sun' - Should be 'Sun' WEEKDAY$('01-01-2001')='Mon' - Should be 'Mon' WEEKDAY$('12-31-2001')='Mon' - Should be 'Mon' WEEKDAY$('01-01-2002')='Tue' - Should be 'Tue' WEEKDAY$('12-31-2002')='Tue' - Should be 'Tue' WEEKDAY$('01-01-2003')='Wed' - Should be 'Wed' WEEKDAY$('12-31-2003')='Wed' - Should be 'Wed' WEEKDAY$('01-01-2004')='Thu' - Should be 'Thu' WEEKDAY$('12-31-04' )='Fri' - Should be 'Fri' |
View [and save] WEEKDAY.BAS text View [and save] ZWEEKDAY.BAS text (Use [Back] button or [Alt]+[CL] to return here from the viewed text) Copyright © 1992–2010 by Go to: Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text top |