How to convert date from 11/23 to 01/11/2023 or 11/2023 to 01/11/2023

Hello friends,

I have to do date conversion where i just receive date as mm/yy Or mm/yyyy

i have to convert it as dd/mm/yyyy.

if it is Manufacture date i have to take it as first date of that month that is 01

and if it is expiry date i have to take it as last date of that month.

image
image

Please help me in this.

Thanks in advance.

Quick Dirty:
grafik

DateTime.ParseExact(YourStringVar, {"MM/yy", "MM/yyyy"}, nothing, nothing).toString("dd/MM/yyyy")
1 Like

Hi @aslam_ali1 ,

Can you try the below in the assign activity?

 Convert.ToDateTime(inputDate).ToString("dd/MM/yyyy")

Hope it works for you.

Happy Automation,
@Vinit_Kawle

Hi @aslam_ali1

=> Use Read Range Workbook to read the excel and store it in a datatable say dtInput.
Input:


=> Use the below syntax in Assign activity:

dtOutput=dtInput.Clone()

=> Use For Each row in Datatable to iterate through dtInput and use below syntaxes in assign activitiy:

MfgDate= DateTime.ParseExact(CurrentRow("Mfg Date").ToString,{"MM/yyyy","MM/yy"},System.Globalization.CultureInfo.InvariantCulture,DateTimeStyles.None)
ExpDate= DateTime.ParseExact(CurrentRow("Exp Date").ToString,{"MM/yyyy","MM/yy"},System.Globalization.CultureInfo.InvariantCulture,DateTimeStyles.None)
StartDate= New DateTime(MfgDate.Year,MfgDate.Month,1).ToString("dd/MM/yyyy")
EndDate= New DateTime(ExpDate.Year,ExpDate.Month,1).AddDays(-1).ToString("dd/MM/yyyy")

Note: MfgDate and ExpDate are of DataType System.DateTime and StartDate and EndDate is of DataType System.String
=> Use Add dataRow acitivty and in ArrayRow pass the below syntax:

ArrayRow -> {StartDate,EndDate}
DataTable -> dtOutput

=> Use Write Range Workbook to write the dtOutput back to excel.
Output:

Workflow:

Hope it helps!

1 Like

grafik

@Vinit_Kawle
done with immediate panel:
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

1 Like

image

is something wrong with it ?

have a look at the resulting year

Thank you @ppr

Your solution always works for me :pray: :smiling_face:

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