Function checkValidDate(dd As Long, mm As Long, yyyy As Long) As Boolean
Dim tmpDate As Date
On Error Resume Next
tmpDate = DateSerial(yyyy, mm, dd)
If Err.Number > 0 Then Exit Function
On Error GoTo 0
checkValidDate = (Day(tmpDate) = dd And Month(tmpDate) = mm And Year(tmpDate) = yyyy)
End Function
? checkValidDate(0, 0, 0)
False
? checkValidDate(10, 7, 1970)
True
? checkValidDate(40, 6, 1970)
False
2条答案
按热度按时间lf5gs5x21#
dateSerial-function的实现目的就是这样的a-如果你想添加天数或月数,它会很方便。
您可以编写自己的检查例程,将日、月和年作为参数,将其作为参数传递给
DateSerial
,并检查日、月和年是否等于您传递的参数值。nfeuvbwi2#
提取并解析文本date并使用
IsDate
: