Date formatting problem

Hi All ,
i have an issue in converting a value from excel in to date time. For some reason excel is saying to UiPath that the given value in a cell is in mm/dd/yyyy… though am using the following statement
datetime.ParseExact(item.Substring(0,item.Length-9),“dd/MM/yyyy”,System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat).Date.ToShortDateString

note : the substring function is used to trim the last 9 characters which has hh:mm:ss.

now though the above instruction is saying "what ever may be the “item” is , just convert first 2 as day second 2 as month an third 4 as year , the excel is saying the first 2 is month .
so if i give something like 13/01/2021 then this conversion itself throws an error. how ever this error do not happen when we change that type of the particular column of the excel into “text”.

Hi @Seetharaman_K

How are u taking input here

Is it from excel

And in what format u need finally?

i need dd:mm:yyyy format. yes am taking from excel.

If u taking date from excel using read range tick the preserve format option in read range

Then date format will be preserved.

Then if the date format in excel is dd/MM/yyyy

Then u can. Convert it to dd.MM.yyyy using below assign activity

date_1= DateTime.ParseExact(row(columnName).ToString,“dd/MM/yyyy”,System.Globalization.CulturalInfo.InvariantCulture).ToString(“dd.MM.yyyy”)

Try this way

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed::relaxed::relaxed:

1 Like