web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Getting inproper date ...
Power Automate
Answered

Getting inproper date from data table to excel sheet.

(0) ShareShare
ReportReport
Posted on by 8

mr_rudra_0-1715000518136.png

I am utilizing the "write to excel workbook" activity to extract the above data table.

It is important to note that this file does not contain any formulas or formatting.

mr_rudra_2-1715001104183.png

 

Upon transcribing the information onto the sheet, I noticed that all five date columns have been altered automatically. Kindly refer to the attached image of the Excel sheet for further clarification.

mr_rudra_1-1715000871641.png

format is getting change from "yyyy-mm-dd" to "mm-dd-yyyy".

So please suggest any workaround for this.

 

I have the same question (0)
  • VishnuReddy1997 Profile Picture
    2,666 Super User 2026 Season 1 on at

    Hi @mr_rudra ,

     

    Your system date format is in dd/MM/yyyy i guess.That's why its populating as dd/MM/yyyy format.

    Simple soltion change your System Date format as yyyy/MM/dd.

     

    If you dont want to change your system date format and to reolve your issue.Please follow the below steps.

    -After writing the data to the excel,Please use these two below actions it will convert your date to yyyy/MM/dd format.

     

    VishnuReddy1997_0-1715058653968.png

    Code:

    Please copy the below code to your flow.

    SET Excel_Filepath TO $'''C:\\Users\\Desktop\\Date_Format_Test.xlsx'''
    @@copilotGeneratedAction: 'False'
    Scripting.RunVBScript.RunVBScript VBScriptCode: $'''Option Explicit
    
    Dim objExcel, objWorkbook, objWorksheet
    Dim strPath, intRow
    
    \' Excel file path
    strPath = \"%Excel_Filepath%\"
    
    \' Create Excel objects
    Set objExcel = CreateObject(\"Excel.Application\")
    objExcel.Visible = True \' Set to True if you want Excel to be visible
    
    \' Open workbook
    Set objWorkbook = objExcel.Workbooks.Open(strPath)
    Set objWorksheet = objWorkbook.Sheets(1) \' Assuming data is on the first sheet
    
    \' Start from the second row
    For intRow = 2 To objWorksheet.UsedRange.Rows.Count
     \' Convert date format for specific columns (E, I, J, K, L)
     objWorksheet.Cells(intRow, \"E\").Value = FormatDate(objWorksheet.Cells(intRow, \"E\").Value)
     objWorksheet.Cells(intRow, \"I\").Value = FormatDate(objWorksheet.Cells(intRow, \"I\").Value)
     objWorksheet.Cells(intRow, \"J\").Value = FormatDate(objWorksheet.Cells(intRow, \"J\").Value)
     objWorksheet.Cells(intRow, \"K\").Value = FormatDate(objWorksheet.Cells(intRow, \"K\").Value)
     objWorksheet.Cells(intRow, \"L\").Value = FormatDate(objWorksheet.Cells(intRow, \"L\").Value)
    Next
    
    \' Save and close workbook
    objWorkbook.Save
    objWorkbook.Close
    
    \' Quit Excel
    objExcel.Quit
    
    \' Clean up
    Set objWorksheet = Nothing
    Set objWorkbook = Nothing
    Set objExcel = Nothing
    
    Function FormatDate(inputDate)
     Dim parts
     parts = Split(inputDate, \"/\")
     If UBound(parts) = 2 Then
     FormatDate = DateSerial(parts(2), parts(1), parts(0))
     Else
     FormatDate = inputDate \' Return original value if not in expected date format
     End If
    End Function''' ScriptOutput=> VBScriptOutput2

     

     

    (Note:- if you got your solution you can mark as solution and gives kudos)


    Thanks & Regards

    Vishnu Reddy

  • kinuasa Profile Picture
    801 Most Valuable Professional on at

    I suggest that executing the script below with the "Run VBScript" action to set the cell format before writing to the cell with the "Write to Excel worksheet" action.

     

     

    GetObject(, "Excel.Application").ActiveWorkbook.ActiveSheet.Range("E:E,I:I,J:J,K:K,L:L").NumberFormat = "yyyy-mm-dd"

     

  • mr_rudra Profile Picture
    8 on at

    Hello Vishnu Reddy, Thanks for the efforts but This is a chat GPT's answer that is not working. and changing the system date is not a feasible option.

  • Verified answer
    kinuasa Profile Picture
    801 Most Valuable Professional on at

    It will take some time, but you can also address it by adding single quotations to each cell as shown below.

    PAD_DatatableToExcel_01.jpgPAD_DatatableToExcel_02.gif

    SET DataTable TO { ^['No', 'Date'], ['1', '2024-01-01'], ['2', '2024-01-02'], ['3', '2024-01-03'], ['4', '2024-01-04'], ['5', '2024-01-05'] }
    Excel.LaunchExcel.LaunchUnderExistingProcess Visible: True Instance=> ExcelInstance
    Excel.SetActiveWorksheet.ActivateWorksheetByIndex Instance: ExcelInstance Index: 1
    LOOP LoopIndex FROM 0 TO DataTable.RowsCount - 1 STEP 1
     Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: DataTable[LoopIndex]['No'] Column: $'''A''' Row: LoopIndex + 1
     Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: $'''\'%DataTable[LoopIndex]['Date']%''' Column: $'''B''' Row: LoopIndex + 1
    END
  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @kinuasa 

     

    100% Agree with time consuming but definitely fantastic approach as there is no proven workaround there and love to learn this tricks from you. 

     

    @mr_rudra 

    Just updated @kinuasa solution by including header details in the excel file.

     

    Deenuji_0-1715138750638.png

    Code:

    SET DataTable TO { ^['No', 'Date'], ['1', '2024-01-01'], ['2', '2024-01-02'], ['3', '2024-01-03'], ['4', '2024-01-04'], ['5', '2024-01-05'] }
    Excel.LaunchExcel.LaunchUnderExistingProcess Visible: True Instance=> ExcelInstance
    Excel.SetActiveWorksheet.ActivateWorksheetByIndex Instance: ExcelInstance Index: 1
    Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: DataTable.ColumnHeadersRow Column: $'''A''' Row: LoopIndex + 1
    SET Rowcounter TO 2
    LOOP LoopIndex FROM 0 TO DataTable.RowsCount - 1 STEP 1
     Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: DataTable[LoopIndex]['No'] Column: $'''A''' Row: Rowcounter
     Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: $'''\'%DataTable[LoopIndex]['Date']%''' Column: $'''B''' Row: Rowcounter
     SET Rowcounter TO Rowcounter + 1
    END

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 262 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 167

#3
Haque Profile Picture

Haque 154

Last 30 days Overall leaderboard