Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vb.net convert string to date

how do i convert the string

30.10.2009 in date? (dd.mm.yyyy)

thanks :>

like image 299
tim Avatar asked Dec 20 '25 14:12

tim


2 Answers

You could 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
like image 137
Darin Dimitrov Avatar answered Dec 23 '25 07:12

Darin Dimitrov


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 datetime format strings on MSDN.

If you are not sure that the format is exactly as mentioned, you can use TryParseExact to avoid an exception being thrown.

like image 39
Oded Avatar answered Dec 23 '25 06:12

Oded



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!