Vb.net convert string to date

how to convert a string

10.30.2009 a day? (Dd.mm.yyyy)

thanks:>

+3
source share
2 answers

You can use the TryParseExact function :

Dim DateStr = "30.10.2009"
Dim Dt As DateTime
If DateTime.TryParseExact(DateStr, "dd.MM.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, Dt) Then
    ' The date was successfully parsed => use the Dt variable
End If
+4
source

You can use DateTime.ParseExact:

Dim culture as CultureInfo = new CultureInfo("en-US")
Dim date as DateTime = DateTime.ParseExact("30.10.2009", "dd.MM.yyyy", culture)

See custom date and time format strings on MSDN.

If you are not sure if the format is exactly specified, you can use TryParseExactit to avoid throwing an exception.

+2
source

Source: https://habr.com/ru/post/1762427/


All Articles