Extract month (mm) and (m) and write in new column

Hi All,
I am reading data from my date column from excel file in the format ( mm/dd/yyyy) & (m/dd/yyyy), spliting it in mm/yy format and again writing in new column.
I am getting error message as " String was not recognized as valid datetime".
Although uipath writes data in my first column.
I need to split " Transaction Date" as mm/yy or m/yy and write to column “Period1”

Attached is the xls file and xaml.

data.xlsx (9.9 KB) Main.xaml (9.8 KB) project.json (686 Bytes)

please check the data type of the variable you are using to read. This error might be a variable type issue.
Also, when/which activity you are getting this error?

Arun : When I am using date parser in the format : M/dd/yyyy, I am able to read first row and write data correctly. In the second row it reads date and before writing, it gives error of datetime format.

If I use date parser as : MM/dd/yyyy, it reads the date from first row and before writing it is giving error.

In my scenario, I have both type of date format.

May be some white spaces are coming while writing new column.
Please use trim method. Hope your problem will be solved.

Hi @Zahid1

Can you try this function when convert string into Datetime
“DateTime.ParseExact(x1, “M/d/yyyy”, System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat)” Main.xaml (9.8 KB)
Kindly let me know the outcome.

@muralirpa : I tried trim, still same error

@Jyotika_Halai : I have used the same code in Main.xaml for date parsing . Still getting error.

Hello, Here is workaround… try to split date into two parts mm and yyyy using Split method and then use the Substring method to get only 2 value from year. For better understanding, go through the video. Split and Substring in UiPath

you have used DateTime.ParseExact(x1,“M/dd/yyyy”,System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat) in your file.

Try: DateTime.ParseExact(x1,“M/d/yyyy”, System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat)

The file provided by me is working for me. Have you run it?

@Jyotika_Halai : It’s working, thanks a lot :).
I have also marked your answer as solution.
Cheers !!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.