Date: 02-16-2022
Return to Index
created by gbSnippets
'This method does not handle leap year (29 Feb)
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Function PBMain () As Long
Local sDate$,s$,m$,d$,y$
sDate$ = "01-01-2014" : S$ = "01234567890" 'sDate$ is string to test, S$ holds allowed characters
Dim DayCount(1 To 12) As Long
Array Assign DayCount() = 31,28,31,30,31,30,31,31,30,31,30,31
If ParseCount(sDate$,"-") = 3 Then 'x-x-x
M$ = Parse$(sDate$,"-",1) : D$ = Parse$(sDate$,"-",2) : Y$ = Parse$(sDate$,"-",3)
If Verify(M$,S$)=0 And Verify(D$,S$)=0 And Verify(Y$,S$)=0 Then ' acceptable characters
If Val(M$) < 13 And Val(M$) > 0 And Val(Y$) > 2010 And Val(Y$) < 2100 Then '2011-2099 year 1-12 month
If Val(Y$) Mod 4 = 0 Then DayCount(2) = 29 'leap year fix
If Val(D$) <= DayCount(Val(M$)) Then 'day count is valid for the month
? "Valid Date"
End If : End If : End If : End If
End Function
'gbs_00827
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm