You can do an 'is date' check. To add it in I've rearranged the code somewhat. The check demands a year between 1601 and 9999.
If Var is Type - Syntax & Usage | AutoHotkey
https://autohotkey.com/docs/commands/IfIs.htm
Code: Select all
Clipboard := "01012000"
;Clipboard := "01012018"
;Clipboard := "01/01/2000"
;Clipboard := "01/01/2018"
;Clipboard := "01/01/1018"
Date := Clipboard
DateOrig := Date
Date := StrReplace(Date, "/") ;remove slashes
Date := RegExReplace(Date, "(..)(..)(....)", "$3$2$1") ;reorder digits to give 'yyyyMMdd' format
;MsgBox, % Date
if Date is date
IsDate := 1
else
IsDate := 0
if !IsDate || !(StrLen(Date) = 8)
{
MsgBox, % "error: invalid/unsupported date:`r`n" DateOrig
return
}
Days := A_Now
Days -= Date, Days
if (Days < 5840)
MsgBox, Under 16
else
MsgBox, Over 16
1018 gave 'Under 16' because the -= operator doesn't support a date before 1601, and gave a blank string, the blank string was considered less than 5840.
Code: Select all
Date := "10180101"
Days := A_Now
Days -= Date, Days
MsgBox, % "[" Days "]"
MsgBox, % (Days < 5840)
Date := "19180101"
Days := A_Now
Days -= Date, Days
MsgBox, % "[" Days "]"
MsgBox, % (Days < 5840)