Date: 02-16-2022
Return to Index
created by gbSnippets
'Knowing which day of the week a date falls on can be very useful.
'Windows provide a couple of API that can do the trick.
'Primary Code:
'Credit: Michael Mattias
Function DayOfWeek(year as Long, month as Long, day as Long) As Long
Local st as SYSTEMTIME, ft AS FILETIME
st.wYear = year
st.wMonth = month ' 1=Jan
st.wDay = day
SystemTimeToFileTime st, ft
FileTimeToSystemTime ft, st
Function = St.wDayofWeek '0 = Sun, 1= Mon
End Function
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Label, hDlg, 130,"9-12-1951", 50,20,100,20
' Control Add Label, hDlg, 130,"9-12-2009", 50,20,100,20
Control Add Button, hDlg, 140,"Push", 50,50,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 140 AND CB.Ctlmsg = %BN_Clicked Then
Local Day As Long, y As Long, m As Long, d As Long, temp$
Control Get Text hDlg, 130 To temp$
y = Val(Parse$(temp$, "-", 3))
m = Val(Parse$(temp$, "-", 1))
d = Val(Parse$(temp$, "-", 2))
Day = DayOfWeek(y,m,d)
MsgBox Choose$(Day+1, "Sun", "Mon","Tue","Wed","Thur","Fri","Sat"), %MB_Ok, "Day of Week"
End If
End Function
Function DayOfWeek(year as Long, month as Long, day as Long) As Long
Local st as SYSTEMTIME, ft AS FILETIME
st.wYear = year
st.wMonth = month ' 1=Jan
st.wDay = day
SystemTimeToFileTime st, ft
FileTimeToSystemTime ft, st
Function = St.wDayofWeek '0 = Sun, 1= Mon
End Function
'gbs_00017
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm