Change data column date format

Have a datatable, which there are 4 columns with date formats of (“dd MMM yyyy”). Anyway i can convert them into the format of yyyy-MM-dd HH:mm:ss, instead of using loops, if there are 1000 rows?

If there are thousands rows then better to.go with this query as assign activitiy below

Like reading the excel file and storing in dt1

then use the following

dt1=dt1.AsEnumerable().ToList().ForEach(Sub(row) row(ColumnName)=DateTime.ParseExact(row(ColumnName).ToString,“dd MMM yyyy”,System.Globalization.CultureInfo
InvariantCulture).ToString(“yyyy-MM-dd HH:mm:ss”))

Mark it as solution of it resolved ur query

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed::relaxed:

Hi it says expression does not produce a value?

Hi use this in invoke code

dt1.AsEnumerable().ToList().ForEach(Sub(row) row(ColumnName)=DateTime.ParseExact(row(ColumnName).ToString,“dd MMM yyyy”,System.Globalization.CultureInfo
InvariantCulture).ToString(“yyyy-MM-dd HH:mm:ss”)). With Language type as vb.net and passing dt1 varaible as in/out argument to.the invoke.code

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed::relaxed:

1 Like

I dont know why im getting this
Invoke code- Reformat date: Exception has been thrown by the target of an invocation.
is it because some rows might be blank/null?

Hi @Username95 - I just tried as per @NIVED_NAMBIAR code…After the cultureInfo you have to add . It should be ‘CultureInfo.InvariantCulture’

dtSample.AsEnumerable().ToList().ForEach(Sub(row) row(“Column2”)=DateTime.ParseExact(row(“Column2”).ToString,“dd MM yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy-MM-dd HH:mm:ss”))

My Input:
image

My Output:

image

If this works, please mark @NIVED_NAMBIAR’s post as solution. Not mine.

1 Like

Hi yes i already added the “.” . I’m not sure if the error is because of some blank rows.

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