Im converting a string “MM/dd/yyyy HH:mm:ss” to a DateTime “yyyy:MM:dd HH:mm:ss” using: Datetime.ParseExact(str_datetime, “yyyy-MM-dd hh:mm:ss”,System.Globalization.CultureInfo.InvariantCulture)
I start of by converting the string to the new format: DateTime.ParseExact(str_datetime, “dd/MM/yyyy HH:mm:ss”, System.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy-MM-dd HH:mm:ss”)
this works ok.
then I convert the new string into a DateTime. using: Datetime.ParseExact(str_datetime, “yyyy-MM-dd hh:mm:ss”,System.Globalization.CultureInfo.InvariantCulture)
this works but the format I get is: “MM/dd/yyyy HH:mm:ss”
can anyone tell me why this is? and what I need to change to get it right?
Sonce your DataType is System.DateTime, this will take the default system format which is MM/dd/yyyy hh:mm:ss.
If you want to convert your string input into a specified required format then the datatype of the output variable will be System.String only. Since you are changing the format of your input into desired format.