Convert from 24 time to 12hr

If I have a string in the format “05/01/2019 20:31:00” how do I convert it to “05/01/2019 8:31 pm” (or similar)
It would also be okay if you tell me how to convert from “20:31:00” to “8:31 pm”

Basically a conversion from 24hr time to 12hr time.

Mydate.ToString(“MM/dd/yyyy hh:mm tt”)

1 Like

@Sami_Syed try below:
for Date and time- Date.ParseExact(stringDate,“MM/dd/yyyy HH:mm:ss”,nothing).ToString(“MM/dd/yyyy hh:mm tt”)

for time only - CDate(mystring).ToString(“hh:mm tt”)


Try below expression:

Datetime.parseexact(“05/01/2019 20:31:00”,“dd/MM/yyyy HH:mm:ss”,System.Globalization.CultureInfo.InvariantCulture).tostring(“dd/MM/yyyy hh:mm tt”)

Here, HH - 24 Hr format
hh - 12 Hr format
tt - AM or PM


This helped me today to convert Jan 24 2021 08:20AM to 24-01-2021.
Thank You so much @lakshman
Great Help.