US date to UK date

Hey all!

I am reading the time and date of an email using “mail.headers” function & storing the info as a string in variable “strDate”, it is in US format.

strDate = 06/15/2020 14:45:43
(US format - MM/dd/yyyy hh:mm:as)

My question is, how do I convert strDate into UK format like this: 15/06/2020 (dd/MM/yyyy)

Thanks!

@Suzana_Joby
ensure following:
grafik

Format Change:

DateTime.ParseExact(strDate, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture).toString("dd/MM/yyyy")
1 Like

Thanks for the quick reply!

This throws an error saying:
“String was not recognized as a valid Date time” :frowning:

@Suzana_Joby
have a look here for validation:

ensure your strDate is valid

2 Likes

ppr’s code is correct but the forum “beautifies” the " character to either or . Use Preformatted Text to prevent that. The code in the quote and the line below can be copy/pasted.

 DateTime.ParseExact(strDate, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture).toString("dd/MM/yyyy")
3 Likes

This works now! I forgot to put hours as HH (I put as hh before)

Thank you! :slight_smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.