Search techniques

  • White belt
  • Standard
  • Tip 6

Format the date directly in utcNow()

Quiz question

What does the expression utcNow('dd.MM.yyyy') return?

Solution

  1. A) The current time in Swiss local timeWrong. The format contains no hours, and utcNow() always works in UTC, not in Swiss time.
  2. B) An error, because formatDateTime() is missingWrong. The expression is valid. utcNow() formats by itself, so the second function is not needed.
  3. C) Today's date in the format day.month.yearCorrect. utcNow() accepts the format as a parameter, so you do not need formatDateTime() for it.

What it is about

Many flows need today's date in a specific format, for a file name or a subject line, for example. Often you find formatDateTime(utcNow(), 'format') in the flow for this. There is a shorter way: utcNow() accepts the format directly as a parameter. utcNow('dd.MM.yyyy') returns the date as day.month.year, without a second function. The result is the same, and the expression is shorter and easier to read. Watch the upper and lower case in the format string: MM stands for the month, mm for the minute. And utcNow() always returns the time in UTC. If you need local time, convert it with convertTimeZone().

The expression from the tip

utcNow('dd.MM.yyyy')

When to use it, when not

Use it

When you need the current point in time in a fixed format, for file names, subject lines or logs, for example.

Better not

When you format a date from a list or an email. For that, formatDateTime() with the value from the source is still the right choice.

Most common mistake

Writing mm instead of MM in the format. The date then shows the minute instead of the month.

License

Standard Runs without a premium connector, so the license from Microsoft 365 is enough. Source on Microsoft Learn: Power Automate licensing FAQ. For your whole flow: License check.

Full tip on powerplatformtip.comPowerPlatformTip #6, with screenshots

Share

Short link: powerautomate.ninja/en/6

Source: PowerPlatformTip #6, Microsoft Learn: Reference for functions in workflow expressions.