Date format error

i want to change 21-06-2022 to 21/06/2022

image

image

image

Hello @Soudios

Can you try the below.

DateTime.ParseExact(string_date.ToString,“dd-MM-yyyy”, Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

Hi,
You can try with:

Date_Piece = Date_Piece.Replace(“-”, “/”)

There is compiler error in Your assign, because You treat It like DateTime variable. It is just string “22-06-2022”, thats why You can’t format It with ToString and specified formatting.

ok but i need it on date time, how can i convert it plz ?

DateTime.ParseExact(str_date.ToString,“MM/dd/yyyy HH:mm:ss”,System.Globalization.CultureInfo.InvariantCulture)

sometimes its dd/MM/yyyy and some times its dd-MM-yyyy

How can i adapt the sentence to works with both ?

for now i am using this : DateTime.ParseExact(Date_Piece,{“dd/MM/yyyy”, “dd/MM/yyyy HH:mm:ss”},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString(“dd-MM-yyyy”)