Convert Date to a Particular Format Regardless of the Source Format

Hi,
I want to convert a string to date with a format like (MM/dd/yyyy) so I used DateTime.ParseExact method as mentioned below.

DateTime.ParseExact(invoiceDate.ToString(),"yyyy-MM-dd", Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")

But just now I realized that the source (invoiceDate) format is dynamic. Sometimes it can be MM/dd/yyyy or dd MMM yyyy or dd-MM-yyyy etc.

is there any way to convert it to MM/dd/yyyy regardless of the source (invoiceDate) format?

@MartianxSpace

You can try with as below

Hope this may help you

Thanks

2 Likes

@MartianxSpace - Please check this post…

1 Like

Yet, it was so simple but I got confused :rofl:.

Here is the solution, it converts the date to (System format) MM/dd/yyyy format

Convert.ToDateTime(dateSource).ToShortDateString

I don’t need the date format here because I want the bot to take the system date format
thank you @Srini84 @prasath17