formatDateTime in Power Automate Desktop

485 Views Asked by At

I am trying to assign the current datetime to two variables in Power Automate Desktop - one as the date in yyyyMMdd format and one as the time in HHmm format.

The steps I have is to use 'Get current date and time' and store that value into the variable CurrentDateTime.

I have then created a variable called Date and I'm setting the variable value to be %formatDateTime(CurrentDateTime,'yyyyMMdd')% and set the time variable to %formatDateTime(CurrentDateTime,'HHmm')%

I keep receiving the error Function name 'formatDateTime' is invalid. What am I doing wrong? Microsoft lists formatDateTime as an expression here https://learn.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#formatDateTime

2

There are 2 best solutions below

1
CobyC On BEST ANSWER

You are confusing Power Automate with Power Automate Desktop. The link you provide is for Power Automate, so those functions won't work in the PADesktop.

There is an action named Convert datetime to text in PAD, you can specify the formats you would like there

The action lets you pick from existing formats or you can specify one. action convert dt to text

copy this code to PAD to see a custom example

Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentDateTime CustomFormat: $'''yyyy*MM*dd HH`mm''' Result=> FormattedDateTime
1
Alfred Jijo On

It seems like you are encountering an issue with the syntax or usage of the formatDateTime function in Power Automate Desktop. Let's break down the steps for setting the Date and Time variables:

  1. Get current date and time:

    • Use the 'Get current date and time' action and store the value into the variable CurrentDateTime.
  2. Format Date:

    • Create a variable called Date.
    • Set the variable value using the following expression:
      %formatDateTime(CurrentDateTime, 'yyyyMMdd')%
      
  3. Format Time:

    • Create a variable called Time.
    • Set the variable value using the following expression:
      %formatDateTime(CurrentDateTime, 'HHmm')%
      

Make sure that you have used the correct syntax for the formatDateTime function, and the variables Date and Time are correctly defined.

If you're still encountering issues, consider the following troubleshooting steps:

  • Double-check the spelling and case of the function and variable names.
  • Ensure that the CurrentDateTime variable is populated correctly after the 'Get current date and time' action.
  • Verify that you are using the correct date and time format strings ('yyyyMMdd' and 'HHmm').

Another thing you could do is:

  1. Get current date and time:

    • Use the 'Get current date and time' action and store the value into the variable CurrentDateTime.
  2. Format Date:

    • Create a variable called Date.
    • Use the 'Format date/time' action and set the format to yyyyMMdd. Input the CurrentDateTime variable as the source, and store the formatted date in the Date variable.
  3. Format Time:

    • Create a variable called Time.
    • Use the 'Format date/time' action and set the format to HHmm. Input the CurrentDateTime variable as the source, and store the formatted time in the Time variable.

Ensure that you are using the available actions in Power Automate Desktop for date and time formatting, as the functions and syntax might differ from traditional expressions.