Issue while formatting date from date time to string

I have a date that i read from excel, which i have to convert from DD/MM to MM/DD.
but i get this error:

Things I have noticed the Date in excel is dd/mm/yyyy,
but in the above screen shot, the bot has read as MM/dd/yyyy.
Any idea why?

I use assign activity

DateTime.ParseExact(String,"dd/MM/yyyy hh:mm:ss”, System.Globalization.CultureInfo.InvariantCulture).ToString(“MM/dd/yyyy”)

Am i doing anything wrong?

@hansen_Lobo

12/16 is the input and you are giving dd/MM month cannot be 16 at all

12/16 is already in MM/dd

Please check the same

Also use HH(24 hr format) instead of hh(12 hr format)

Cheers

Thanks, i just noticed.

But Date in excel is dd/mm/yyyy,
but in the above screen shot, the bot has read as MM/dd/yyyy.
Any idea why?
image

@hansen_Lobo

The excel format is just a frontend representation…everytime you need to check the actual format once you read into datatable which is the actual backend value that excel stores

Cheers

how to check which format i am getting the date in?

@hansen_Lobo

Once you read the data into datatable using read range…open the locals panel and you can check the datatable data…

Cheers

yeah, thats one of the way, is there anyway i can know it in code, so i can put conditions if its in DD/MM or MM/DD accordingly

@hansen_Lobo

That would work if the date is 12/16 like this but if date is below 12 then it might not be reliable…

The input date format generally does not change unless the timezones change…as excel stores the date in the current timezone format

Cheers

Thank you Anil,
Thanks for the clarifications

1 Like

@hansen_Lobo

if its resolved please close the topic else happy to help

cheers

:ambulance: :sos: [FirstAid] Datatable: Debug & Analysis invalid DateTime Strings / String to DateTime Parsing Issues - News / Tutorials - UiPath Community Forum

later it is describing how to parse multiple formats in one go