How to convert "20200805 055959" to ""05-08-2020 05:59:59"" using Datetime parse

Hello guys i am trying to convert date time string “20200805 055959” to "“05-08-2020 05:59:59"”
using DateTime.ParseExact(StringDateStamp, “yyyymmdd hhmmss”, Nothing).ToString(“dd-mm-yyy hh:mm:ss”)

its not working, please someone help me out , i think i am missing something

Thanks

I think you want DateTime.ParseExact(StringDateStamp, “yyyymmdd hhmmss”, System.Globalization.CultureInfo.Invariantculture).ToString(“dd-mm-yyyy hh:mm:ss”).

@Anthony_Humphries can you please help with a sample sequence i tried it, it still doesn’t work :sweat_smile:

Oh it worked , i had to capitalize the HH time and the MM for months. I am surprised. do capitalization really matter when writing this code
Here is it now
DateTime.ParseExact(“20200805 055959”, “yyyyMMdd HHmmss”, System.Globalization.CultureInfo.Invariantculture).ToString(“dd-mm-yyyy HH:mm:ss”)

1 Like

Yes capitalization is quite important. Please see all the available formats you can use at this link: Custom date and time format strings | Microsoft Learn

1 Like