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

studio
variable

#1

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


#2

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”)


#3

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


#4

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

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

Hope this helps


#5

can I do it in one line of code?


#6

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

Thanks to @vvaidya


#7

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