开发者

isDate control on european data in vb.net

开发者 https://www.devze.com 2022-12-12 03:56 出处:网络
How can i do a isDate() control开发者_高级运维 on a date like 16/01/2008 in vb.net?To check if 16/01/2008 is a valid date, you do:

How can i do a isDate() control开发者_高级运维 on a date like 16/01/2008 in vb.net?


To check if 16/01/2008 is a valid date, you do:

Dim result As Date
If Date.TryParse("16/01/2008", result) Then
     'The date is valid '
End If

Now this will use the current culture set. If you want to validate it against a specific culture, you can do it like this (example with french culture):

If Date.TryParse("16/01/2008", Globalization.CultureInfo.GetCultureInfo("fr-FR"), _
                 Globalization.DateTimeStyles.None, result) Then
    'The date is valid '
End If


If the date format in your input data is fixed to month/day/year and does not depend on the current culture, you should use DateTime.TryParseExact:

Public Shared Function IsValidInputDate(ByVal str As String) As Boolean
    Dim dt as DateTime
    Return DateTime.TryParseExact(str, "d/M/yyyy", Nothing, Globalization.DateTimeStyles.None, dt)
End Function
0

精彩评论

暂无评论...
验证码 换一张
取 消