Error in Date Format

To All Who Are Willing to Help:

I had this column in my generated report “PR Creation Date” and contained thousands of rows (~7k rows). I wanted to automate the date format of this column cells containing “dd-MMM-yy” format but there was an error in its current state. Message Error shown: *This cell contains a date string represented with only 2 digits for the year. *

What I want is to convert these cells all at once as per Excel prompt suggestion: Convert XX to 20XX. Doing this manually can be so tedious since it contains thousands of rows. So, automating it might lessen the job.

How can I get this done? What activities best suited to get this done all at once?

Please advise.

Thank you.

image
image
image
image

HI @jharmel.carmona

Can you check out the thread

Regards
Gokul

1 Like

Hi @jharmel.carmona

Try this:

  1. Use the “Read Range Workbook” activity to read the data from the worksheet containing the “PR Creation Date” column. This will read the data into a DataTable variable.
  2. Use a “For Each Row in Data Table” activity to loop through each row in the DataTable.
  3. Use the below syntax in Assign activity:
CurrentRow("PR Creation Date") = DateTime.ParseExact(CurrentRow("PR Creation Date").ToString, "dd-MMM-yy", System.Globalization.CultureInfo.InvariantCulture).ToString("dd-MMM-20yy")
  1. Use Write Range Workbook to write it back to excel.

hope it helps!!

1 Like

Have you tried with format cell activity

Check out this thres

https://forum.uipath.com/search?q=format%20cell%20activity

Regards
Gokul

1 Like

You can also try with Invoke VBA activity @jharmel.carmona

dt.AsEnumerable.ToList.ForEach(Sub(x) x("PR Creation Date") =  DateTime.ParseExact(CurrentRow("PR Creation Date").ToString, "dd-MMM-yy", System.Globalization.CultureInfo.InvariantCulture).ToString("dd-MMM-20yy")).ToString.trim)

Regards
Gokul

1 Like

Hi @jharmel.carmona

Read Range (Output: dtData)

dtUpdatedData = (From row In dtData.AsEnumerable()
                    Let dateColumn = row("PR Creation Date").ToString()
                    Where dateColumn.Contains("-") AndAlso IsTwoDigitYear(dateColumn)
                    Select row).CopyToDataTable()
For Each Row (ForEachRow in dtUpdatedData)
    Row("PR Creation Date") = FormatDate(Row("PR Creation Date").ToString())

Write Range

1 Like

Hi,

Can you try the following sample?

dt.AsEnumerable.ToList.ForEach(Sub(r)
    r("PR Creation Date") = r("PR Creation Date").ToString.Insert(  r("PR Creation Date").ToString.LastIndexOf("-")+1,"20")
End Sub
)

Sample
Sample20231004-4L.zip (9.3 KB)

Regards,

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