Returns a Boolean value indicating whether an argument contains a Date type.
Bool = IsDate(exp)
exp | : Variant, Date, or String expression |
IsDate returns True if the expression is a date or is recognizable as a valid date; otherwise, it returns False. In Microsoft Windows, the range of valid dates is January 1, 100 A.D. through December 31, 9999 A.D.; the ranges vary among operating systems.
NOTE: IsDate recognises dates without the year value and assumes that the year is the current year (e.g. 12/12 as 12th December of this year).
Local z As Date = HmsToTime(110000, 20, 4000)
Print IsDate(z) // True
Print IsDate(#16.12.1912#) // True
Local b$ = "31/12/2000"
Print IsDate(b$) // -1 -> True
Local c As Variant = "23/25/1943"
Print IsDate(c) // 0 -> False
Print IsDate("12/12") // -1 -> True (IsDate recognises this as day and month of current year)
...and...
Dim SomeDate, daysleft
Ocx Label lbl = "Enter Date:", 10, 10, 60, 14 : lbl.BackColor = RGB(255, 255, 255)
Ocx TextBox Text1 = "", 70, 9, 100, 14 : .BorderStyle = 1
Ocx Command cmd = "Calculate", 175, 7, 70, 18
Ocx Label Text2 = "", 10, 30, 200, 14 : Text2.BackColor = RGB(255, 255, 255)
Do : Sleep : Until Me Is Nothing
Sub cmd_Click
If IsDate(Text1.Text) Then
SomeDate = CDate(Text1.Text)
daysleft = Int(DateSerial((Year(SomeDate) + 1, 1, 1,)) - SomeDate)
Text2.Text = daysleft & " days left in the year."
Else
MsgBox Text1.Text & " is not a valid date."
End If
EndSub
Sub Text1_KeyPress(Ascii&)
Text2.Text = ""
EndSub
IsDate, IsEmpty, IsError, IsMissing, IsNull, IsNumeric, IsObject
{Created by Sjouke Hamstra; Last updated: 18/09/2021 by James Gaite}