
FB II Compiler
PG PRO
Debugging
Memory
System
Mathematics
Resources
Disk I/O
Windows
Controls
Menus
Mouse
Keyboard
Text
Fonts
Drawing
Sound
Clipboard
Printing
Communication
ASM
|
MATHEMATICS
Find the day of the week
I discovered this goodie, which could be useful to many of us, amongst the FB archives. It appears to be exactly what I'm looking for, but I can't find the key to extracting the day. Clues, anyone?
'==========================
' dayofweek - Calculate day of the week index
' At entry dd=date, mm=month, yy=year in format nnnn e.g. 1991
' this date should first be validated
' At exit z=index to day of the week (1=Sunday, 7=Saturday)
' routine valid for dates 1-1-1583 through 12-31-9999
'Subj: Re:Day of Week Clarification
'Date: 96-03-15 18:18:44 EST
'From: WatsonR
'==========================
LOCAL FN DayOfWeek(mm,dd,yy)
t!=1/mm
k1=0.6+t! : l1=yy-k1
t!=12*k1
o1!=mm+t! : p1#=l1/100
z1=INT(p1#/4) : z2=INT(p1#) : z3=INT((5*l1)/4)
z4=INT(13*(o1!+1)/5) : z=z4+z3-z2+z1+dd
z=z-(7*INT(z/7))
END FN=z
'----------
dayNum% = FN DayOfWeek(3,18,1999) 'for March 18, 1999
SELECT CASE dayNum%
CASE 1: day$ = "Sunday"
'
'
CASE 7: day$ = "Saturday"
END SELECT
Warren Furman
Here's what I use and it still works. The Year is in 4 digits (1999) not PC format.
LOCAL FN Date2Julian&(Day, Month, Year)
'
LONG IF Month<3
Month=Month+12
DEC(Year)
END IF
INC(Month)
'
Julian&=(365.25*Year)+(30.6001*Month)+Day+1720982
'
END FN = Julian&
'
LOCAL FN DayOfWeek$(Julian&)
SELECT CASE Julian& MOD 7
CASE 0
DayOfWeek$ = "Monday"
CASE 1
DayOfWeek$ = "Tuesday"
CASE 2
DayOfWeek$ = "Wednesday"
CASE 3
DayOfWeek$ = "Thursday"
CASE 4
DayOfWeek$ = "Friday"
CASE 5
DayOfWeek$ = "Saturday"
CASE 6
DayOfWeek$ = "Sunday"
END SELECT
END FN = DayOfWeek$
'
LOCAL FN BuildDate$(M,D,Y): ' builds date string from MONTH,DAY,YEAR
DateStr$="..-..-....": ' cancel out the old one first
MID$(DateStr$,1,2)=RIGHT$(STR$(M),2):' extract the month first
MID$(DateStr$,4,2)=RIGHT$(STR$(D),2):' extract the day next
MID$(DateStr$,7,4)=RIGHT$(STR$(Y),4):' extract the year last
IF MID$(DateStr$,1,1)=" " THEN MID$(DateStr$,1,1)="0":' add in a zero
IF MID$(DateStr$,4,1)=" " THEN MID$(DateStr$,4,1)="0":' add in second zero
END FN = DateStr$
'
LOCAL FN Julian2Date$(Julian&)
U&=Julian&+68569
V&=INT(4*U&)/146097
U&=-INT(((146097*V&)+3)/4)+U&
Y&=INT(4000*(U&+1))/1461001
U&=-INT((1461*Y&)/4)+31+U&
M&=INT(80*U&)/2447
D&=-INT((2447*M&)/80)+U&
U&=INT(M&/11)
M&=-12*U&+2+M&
Y&=100*(V&-49)+Y&+U&
Year=Y&:Month=M&:Day=D&
DateStr$= FN BuildDate$(Month,Day,Year)
END FN=DateStr$
Mel Patrick
Heres a bright idea, lets use the toolbox to do it all for us, its much = less code...
DIM myDateRec.DateTimeRecSize
myDateRec.Day% = 17
myDateRec.Month% = 10
myDateRec.Year% = 1999
myDateAsSeconds& = FN DATE2SECS(@myDateRec)
CALL SECS2DATE(myDateAsSeconds&,@myDateRec)
PRINT "Day Of Week as Number: ";myDateRec.DayOfWeek%
Jamin
|