Updating all the rows in excel with Date

Hi All,
I have a datatable called Marketplace . one of the column is Bot Modified Date . i want to updated all the rows in that column with today’s date . i am using the below code in assign statement
MarketDT.Columns(“Bot Modified Date”).Expression=System.DateTime.Now.ToString(“MM-dd-yyyy”)

but when i try to write the dt value for Bot Modified Date comes as -2047


please help

@tharani.natarajan,

Is date reflecting in Datatable in studio correct? you can check it from local panel.

If it’s correct then follow below steps.
It seems Excel format. Once you write the Datatable to Excel, Use Activities - Format Cells to format the Column with this format: “MM-dd-yyyy”

Thanks,
Ashok :slight_smile:

even in studio it is -2047

Hi @tharani.natarajan

Try this

Code:

For Each row1 As DataRow In DT.Rows
    row1("Bot Modified Date") = DateTime.Now.ToString("MM-dd-yyyy")
Next

Output:

Cheers!!

1 Like

Thanks for the response. Can we do it without going into for each ?

@tharani.natarajan,

Ok in that case Expression is not working. Instead of Datatable expression use below LINQ query to update Datatable Column value using Invoke Code:

MarketDT.AsEnumerable().ToList().ForEach(Sub(row) row("Bot Modified Date") = Now.ToString(“MM-dd-yyyy”))

Thanks,
Ashok :slight_smile:

1 Like

@tharani.natarajan

I am not using For each activity Invoke Code activity takes it to iterate all rows

Regards,

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