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)


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


can I do it in one line of code?


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

Thanks to @vvaidya


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