Hi.
i made automation for my work.
everyday, my rpa visit the web site and extract data and save it in the excelfile.
but problem is that there is no date in the data table.
i try to insert date column but there is no way in automate desktop.
is there any way to insert date column in data table?
Thanks a lot. It is works perfectly!
If VishnuReddys1997's solution doesn't work for you then you could use Run .NET script with C# and add Date column with todays date as default value.
Add Run .NET script -action:
Language C#
Press Script parameters Edit -button and this window opens:
Input those parameters. Just remember to change the Input value to the dataTable that you are using
Then add .NET code to run:
// Add a column with default value set to DateTime.UtcNow.Date
DataColumn dateColumn = new DataColumn("Date", typeof(DateTime));
dateColumn.DefaultValue = DateTime.UtcNow.Date;
dt1.Columns.Add(dateColumn);
// Convert DataTable to DataView and then back to DataTable
dt1 = dt1.DefaultView.ToTable();
Or just copy paste this action to your PAD and change the Script parameters Input Value to your dataTable
Scripting.RunDotNetScript Language: System.DotNetActionLanguageType.CSharp Script: $'''// Add a column with default value set to DateTime.UtcNow.Date
DataColumn dateColumn = new DataColumn(\"Date\", typeof(DateTime));
dateColumn.DefaultValue = DateTime.UtcNow.Date;
dt1.Columns.Add(dateColumn);
// Convert DataTable to DataView and then back to DataTable
dt1 = dt1.DefaultView.ToTable();
''' @'name:dt1': InputDataTable @'type:dt1': $'''Datatable''' @'direction:dt1': $'''InOut''' @dt1=> dtOut
Table before Date column:
After adding Date column:
Hi @dexter2 ,
As per my understanding,instead of adding Date&Time column to DataTable,add the column to the excel and write the current date and time to each row.
Please find the attached solution.
Code:
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Users\\OneDrive\\Desktop\\Power Automate Desktop\\input.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance
Excel.InsertColumn Instance: ExcelInstance Column: $'''DateandTime'''
Excel.ReadFromExcel.ReadAllCells Instance: ExcelInstance ReadAsText: False FirstLineIsHeader: True RangeValue=> ExcelData
SET RowValue TO 2
LOOP FOREACH CurrentItem IN ExcelData
Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: CurrentDateTime Column: $'''B''' Row: RowValue
Variables.IncreaseVariable Value: RowValue IncrementValue: 1
END
(Note:- if you got your solution you can mark as solution and gives kudos)
Thanks & Regards
Vishnu Reddy
Michael E. Gernaey
497
Super User 2025 Season 2
David_MA
436
Super User 2025 Season 2
Riyaz_riz11
244
Super User 2025 Season 2