Problem with a data

Hello group, I start by saying that I’m using dates and that up to now I’ve been able to write my code without problems … now I’m having a problem with writing a function, where I pass the value of my date (I can decide whether to pass it as date or as string) from a textfield in the format dd/mm/YYYY.

MyDate = 01/12/2022 01=Day 12=month 2022=year

Function … (Quando as string)

Dim Year as integer
DIm Month as integer
Dim Day as integer

Dim PartiDellaData() as string=Split(Quando.ReplaceAll(" “,”“),”/")
Day=PartiDellaData(0).ToInteger
Month=PartiDellaData(1).ToInteger
Year=PartiDellaData(2).ToInteger

messagebox day.ToText + " / " + " / " + month.ToText + " / " +year.ToText

Dim Temp_Quando as Date

Quando=Year.ToText+“/”+month.ToText+“/”+day.totext
Temp_Quando=datetime.FromString(Quando)

messagebox " OK DATA Quando="+Temp_Quando.ShortDate


I’ve also tried passing it as
Dim Temp_Quando as Date
Temp_Quando=DateTime.FromString(Quando)

ma mi ritorna sempre un errore.
Immagine

the docu tell us we should use DateTime (not Date)

the message told you using - not /

Markus makes mention of it, but it’s hard to catch. Date and DateTime are different classes. The framework being able to silently convert the classes for you is actually causing confusion here.

DateTime.FromString is not as flexible as the API 1 framework’s ParseDate function. You must provide the API 2 function a locale so that the function knows how to decipher nn/nn/nnnn.

You are declaring Temp_Quando as a Date, then using the DateTime function to parse the string. You can either revert to using the API 1 function ParseDate, or you can update your code to use DateTime. Since you have the individual values you should construct the object more specifically:

var dtQuando as new DateTime(Year, Month, Day)
1 Like

try
DateTime.FromString(dateValue, Locale.Current)

Thanks everyone for the info. Finally I used the “,LocalE.Current)” which converts the date to my format and then allows me to compare against the data in my database. Now everything works. Thank you.