Problem with datetime.fromstring and locale.current

if i use this code :

dim d as datetime
d= datetime.fromstring(“01/10/2023 17:21:12” , locale.current ) // local.current like italy

here the value of d.sqldatetime is =“2023-10-01 00:00:00”
the orginal hour,minutes,seconds value are ignored an set to 00:00:00

Try changing:

d= datetime.fromstring("01/10/2023 17:21:12" , locale.current ) // local.current like italy

to

d= datetime.fromstring("01/10/2023, 17:21:12" , locale.current ) // local.current like italy

You can test this by doing ToString tests, like:

Dim d As New DateTime(2023,10,1,17,21,12)
Dim local As New Locale("it-IT")
Dim s As String = d.ToString(local) // 1 ott 2023, 17:21:12
s = d.ToString(local, datetime.FormatStyles.Short) // 01/10/23, 17:21:12

The string to be used with FromString must match what ToString can produce.

1 Like