Power Automate: date and time

To know how to get and to format the date and time, it is very useful, particularly, if I want to create for instance, a folder or a file in which the name should include the year or the current month.

After selecting the kind of trigger I want, I will click on the “+” to add a new step:

power automate

In the “search” field, put “compose” to select this option:

power automate

Click on the “inputs” field then on the “fx” button:

power automate

Put this code (it will give the current date and time in UTC) then click on “add”:

formatDateTime(utcNow(),'dd/MM/yyyy HH:mm:ss tt')

power automate power automate

IMPORTANT: it is important to respect capital or lowercase characters if not I will not get the correct result:

  • For day: it can be “dd” or “d”
  • For month: it can be “MM” (number), “MMM” (short name) or “MMMM” (full name)
  • For year: it can be “yy” (short number) or “yyyyy” (full number)
  • For hour: it can be “H” or “HH”
  • For minute: it should be “mm”
  • For seconds: it should be “ss”
  • Optional: to add AM/PM, keep “tt” or remove it

NOTE:

  • By default, it shows in UTC so to convert it to another time zone, I have to add a step
  • If I prefer another order or format, just change it, for instance instead of “dd/MM/yyyy HH:mm:ss tt”, I can put “MMM dd yy H:mm”

To convert to another time zone, click on the “+” then put “convert time zone” to select this option:

power automate power automate

To fill the fields:

  • For “base time”, click on the “lightning” icon to select this option:
    power automate power automate
  • For “source time zone”, let it “UTC”
  • For “destination time zone”, select your time zone
  • For “time unit”, select one of the options or to enter a specific format, select “enter custom value”, for instance, “MMM dd yyyy HH:mm:ss CET”
    power automate
power automate

To test it, just add another step, for instance “send an email”, read Power Automate: add a picture in an email

Now, if I want to use it for the creation of a folder or a file, I will need to convert it into a string, in such situation, I will add a step, before or after the email test step:

power automate power automate

NOTE: if I put if after the email test step, I can’t use it for my email

After clicking on the “+”, put “initialize” to select:

power automate

For the fields:

  • Name: put whatever I want, for my article, “name4folder
  • Type: select “string”
  • Value: click on the “lightining” icon to select either “outputs” or “converted time”, for my article, I will select the second one
    power automate
power automate

To know how to create a folder, read Power Automate: create a folder in sharepoint and/or for a file, read Power Automate: create an excel file in sharepoint.

Interesting Topics