Get the System Date Format

Hi All,
How to get the system date format?
eg : Input - 01/28/2020
Output - MM/dd/yyyy

1 Like

Now.ToString("MM/dd/yyyy") for the current date

If 01/28/2020 is a string, then Datetime.ParseExact("01/28/2020", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture).

If 01/28/2020 is a datetime MyDatetime, then MyDatetime.ToString("MM/dd/yyyy").

@Anthony_Humphries
Thanks for your response. I need to only the get format from date not to change the format.

The format cannot be determined from a string. However, you can write logic to guess what the format is. For instance, if you use TryParseExact, you can get a boolean indicating if the format you tried was successful.

So there is no way to get the format. And help with TryParseExact query

TryParseExact requires the following parameters:

1.) The string you’re trying to parse
2.) The format of the date you’re looking for
3.) The CultureInfo to use (normally System.Globalization.CultureInfo.InvariantCulture is sufficient
4.) The Datetime style (normally DatetimeStyle.None is sufficient)
5.) The Datetime variable in which the converted datetime is stored.

The function returns True if the parse was successful, or False if not.

Here is the documentation:

@Kabeer I also have the same query, I need to get the system format first then convert current date into that format and pass into the application because application accepts system date format only