Change datatable column type number to date

i have column in data table containing yyyyMMdd format which i want to convert in dd-MM-yyyy.
And getting error in following Linq
DT1.AsEnumerable().Select(Function(row) DT1.Rows.Add(DateTime.ParseExact((“DATE_OF_BIRTH”).ToString(), “yyyyMMdd”, System.Globalization.CultureInfo.InvariantCulture).ToString(“dd-MM-yyyy”), True)).CopyToDataTable()

Hi @Lalit_Chaudhari,

This is the correct query you can try:
DT1.AsEnumerable().Select(Function(row)
DT1.Clone().LoadDataRow(
{DateTime.ParseExact(row(“DATE_OF_BIRTH”).ToString(), “yyyyMMdd”,
System.Globalization.CultureInfo.InvariantCulture).ToString(“dd-MM-yyyy”)}, True)
).CopyToDataTable()

1 Like

Is the column in DateTime format or String?

1 Like

Hi @Lalit_Chaudhari

Follow the below steps to convert the date style by using vb expression,
→ Use the Read range workbook activity to read the excel and store in a datatable called dt.
→ Then use the Invoke code activity, click on edit code and give the below code,

For Each row As datarow In dt.AsEnumerable
row("DATE_OF_BIRTH") = DateTime.ParseExact(row("DATE_OF_BIRTH").ToString, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture).ToString("dd-MM-yyyy")
Next

→ Click on Edit arguments and give dt in name, select datatable as variable type, select In option in direction dropdown, pass dt variable in value field.
→ Then use the Write range workbook activity to write the datatable to excel.

Hope it helps!!

1 Like

@Lalit_Chaudhari

  1. Please specify the rror
  2. Did you check the format from locals panel? If yes then thats correct else it might be that the format is different
  3. Are there any blank values? If yes then those are to be handled

Cheers

1 Like

It’s in Number format

Thank you for helping me
already used same approach

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