Date formating MM/dd/yyyy 00:00:00 to yyyy-MM-dd

Hi I have a string variable str1=“MM/dd/yyyy 00:00:00”. I wanna convert it to “yyyy-MM-dd”

Convert your string to DateTime and then format it

str1=“MM/dd/yyyy 00:00:00”
tempDate = Convert.ToDateTime(str1)
tempDate.ToString(“yyyy-MM-dd”)

6 Likes

thanks… It worked… I’m also trying to rearrange a string from “LastName, FirstName” to “FirstName LastName”

Split the string based on “,” and then concatenate the array:

strArr = str.Split(",“c)
str = strArr(1).ToString+” "+strArr(0).ToString

Hope this helps

2 Likes

can I do it in one line of code?

String.Join(" “,Split(str,”,").Reverse)

Thanks to @vvaidya

2 Likes

Thanks. I’ll try it later and let you know.

thx Priya,
but my date-string is in german format “dd.MM.yyyy”.
Convert.ToDateTime(“31.01.2022”) doesn’t recognize it. I tried DateTime.TryParse but UiPath doesnt understand CultureInfo.
Any Ideea to avoid the String parse in 3 vars for dd, MM, yyyy?