Function Reference

_DateIsValid

Checks the given date to determine if it is a valid date.

#include <Date.au3>
_DateIsValid ( $sDate )

 

Parameters

$sDate The date to be checked.

 

Return Value

Success: Returns 1.
Failure: Returns 0 if the specified date is not valid.
@Error: 0 = No error.
1 = Invalid date format.
2 = Badly formed month.
3 = Badly formed day.
4 = Badly formed year.
5 = Month is out of range.
6 = Day is out of range.
7 = Year is out of range.
8 = Not a leap year.

 

Remarks

This function takes a date input in one of the following formats:

    m/d/yy, m/d/yyyy, mm/dd/yy, mm/dd/yyyy
    d.m.yy, d.m.yyyy, dd.mm.yy, dd.mm.yyyy
    m_d_yy, m_d_yyyy, mm_dd_yy, mm_dd_yyyy
    yy-m-d, yyyy-m-d, yy-mm-dd, yyyy-mm-dd

The function recognizes the date format used automatically from the delimiter character used in the given date string.
If the given date is invalid, the function will return a -1 and set @error to a positive number depending on how the specified date was invalid.
If the given year is only 2-digits long, the function assumes that it will be in the 2000-2099 range. For all other date ranges, a 4-digit year must be specified.

The function works for all dates between 1753 and 2999 (before this there was another calender - Gregorian vs. Julian).

 

Related

None.

 

Example


#include <Date.au3>

$sDate = @MON & "/" & @MDAY & "/" & @YEAR

If _DateIsValid( $sDate ) Then
  MsgBox( 4096, "Valid Date", "The specified date is valid." )
Else
  MsgBox( 4096, "Valid Date", "The specified date is invalid." )
EndIf