Skip to main content
Community site session details

Community site session details

Session Id : UQ1kEZPIwqrZrutsNIieRk
Power Automate - Power Automate Desktop
Answered

add today date column in the data table

Like (0) ShareShare
ReportReport
Posted on 29 Apr 2024 08:09:06 by 22

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? 

 

 

dexter2_0-1714377911812.png

 

  • dexter2 Profile Picture
    22 on 30 Apr 2024 at 03:38:26
    Re: add today date column in the data table

    Thanks a lot. It is works perfectly!

  • Verified answer
    eetuRobo Profile Picture
    3,685 Super User 2025 Season 2 on 29 Apr 2024 at 09:30:34
    Re: add today date column in the data table

    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:

    eetuRobo_5-1714382927472.png

    Input those parameters. Just remember to change the Input value to the dataTable that you are using

    Then add .NET code to run:

    eetuRobo_3-1714382729908.png

    // 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:

    eetuRobo_2-1714382692563.png

     

    After adding Date column:

    eetuRobo_1-1714382666987.png

     

  • VishnuReddy1997 Profile Picture
    2,526 Super User 2025 Season 2 on 29 Apr 2024 at 08:30:08
    Re: add today date column in the data table

    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.

     

    VishnuReddy1997_0-1714379339371.png

     

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 2

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 2

Loading complete