How to get the Format from Date

Hi Everyone,

I am trying to get the system Date Format .
The available code : CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern gives the format as MM-dd-yyyy always .

I am trying to figure out how to get the expected result .

Trying the below specified solution :

  1. Fetching the system date from System tray
    2)Converting the date string to a proper date variable and using .GetDateTimeFormat method

This solution gives me error as the string to date conversion is throwing error .(String was not recognized as valid date)

Please suggest .

Thanks and Regards
Sushree Suravi

@sushree.suravibuyan

Could you please tell me which format you want ?

Hi
Welcome back to uipath community
If your date format is like this with str_input string variable
“MM/dd/yyyy hh:mm:ss” or “MM/dd/yyyy”
Then this expression would help you get the desired date format you want
str_output = DateTime.ParseExact(str_input.Substring(0,10),”MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“your required date format”)
Like .ToString(“dd/MM/yyyy”)

Or
If your str_input is of this format
“dd/MM/yyyy hh:mm:ss” or “dd/MM/yyyy”
Then the str_output would be
DateTime.ParseExact(str_input.Substring(0,10),”dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“your required date format”)

Hope this would help you
Cheers @sushree.suravibuyan

Hi @Palaniyappan

Thank you very much for quick response .

The requirement is not to convert the date format . I want to find out in which format the system Date is. like whether the format is “MM/dd/yyyy” or “dd/MM/yyyy”.

Regards
Suravi

1 Like

yyyyMMddHHmmss (20200107121104)

1 Like