Power Automate Date & Time Formatting, Functions, Actions

Power Automate Date Time-Formatting Functions Actions

Working with date and time in Power Automate flows can be challenging. This article aims to give you a complete overview and a reference on how to format and manipulate dates and time within a Power Automate flow.

I tried to address every topic around dates and time within Power Automate: Formatting, Functions/ Expressions, Actions and common use cases. Nevertheless I appreciate your feedback in the comments in case something is missing, wrong, outdated etc.

At the end of this article you should have a complete overview on all Power Automate date functions.

In case you want to navigate to a certain topic. Just use the table of content for navigation.

Formatting

Learn how to format dates in Power Automate.

The formatting of dates in Power Automate is done by providing a format string. At first these format strings might be confusing, but you’ll get used to it.

Let’s take a look at an example!

// Returns for example: March Thursday 09:12
formatDateTime(utcNow(), 'MMMM dddd HH:mm', 'en-en') 

// Returns for example: marzo jueves 09:13
formatDateTime(utcNow(), 'MMMM dddd HH:mm', 'es-es') 

To understand how these formats are used, browse to year, month, day, hour or seconds to find what you need.

formatdatetime power automate
formatDateTime Power Automate

Year

FormatDateFormatted Date
y0001-03-011
y2000-11-150
y2022-03-0122
yy0001-03-0101
yy2000-11-1500
yy2022-03-0122
yyy0001-03-01001
yyy0090-03-01090
yyy2022-03-012022
yyyy0001-03-010001
yyyy2022-03-012022
yyyyy2022-03-0102022

Month

FormatDateFormatted Date
M2022-03-013
M2022-11-1511
MM2022-03-0103
MM2022-11-1511
MMM2022-03-15Mar
MMMM2022-03-15March

Days

FormatDateFormatted Date
d2022-03-011
d2022-03-1515
dd2022-03-0101
dd2022-03-1515
ddd2022-03-15Tue
dddd2022-03-15Tuesday

Hours

FormatTimeFormatted Time
h01:301
h11:3011
hh01:3001
hh11:3011
hh13:3001
H01:301
H13:3013
HH01:3001
HH13:3013
t01:30A
t13:30P
tt01:30AM
tt13:30PM

Minutes

FormatTimeFormatted Time
m01:022
m11:3030
mm01:0202
mm11:3030

Seconds

FormatTimeFormatted Time
s01:00:022
s11:00:3030
ss01:00:0202
ss11:00:3030

Functions

There are a couple of Power Automate date functions. Within the following paragraphs, all date operations are introduced. Get to know the syntax of the functions and learn by concrete examples. Understand all Power Automate flows functions.

addDays

Adds an integer number of days to a string timestamp passed in.

Syntax

addDays(timestamp, days, format?)

Examples

// add 14 days to current date
addDays(utcNow(),14) 

// subtract 14 days from current date
addDays(utcNow(),-14) 

// with format, example '2022-03-26'
addDays(utcNow(),14,'yyyy-MM-dd') 

Learn more about the Power Automate addDays function!

addHours

Adds an integer number of hours to a string timestamp passed in.

Syntax

addHours(timestamp, hours, format?)

Examples

// add 5 hours to now
addHours(utcNow(),5) 

// subtract 5 hours from now
addHours(utcNow(),-5) 

// with format, example '2022-03-26 08:58'
addHours(utcNow(),5,'yyyy-MM-dd HH:mm') 
addhours power automate
addHours Power Automate

addMinutes

Adds an integer number of minutes to a string timestamp passed in.

Syntax

addMinutes(timestamp, minutes, format?)

Examples

// add 5 minutes to now
addMinutes(utcNow(),5) 

// subtract 5 minutes from now
addMinutes(utcNow(),-5) 

// with format, example '2022-03-26 08:58'
addMinutes(utcNow(),5,'yyyy-MM-dd HH:mm') 

addSeconds

Adds an integer number of seconds to a string timestamp passed in.

Syntax

addSeconds(timestamp, seconds, format?)

Examples

// add 5 seconds to now
addSeconds(utcNow(),5) 

// subtract 5 seconds from now
addSeconds(utcNow(),-5) 

// with format, example '2022-03-26 08:58:17'
addSeconds(utcNow(),5,'yyyy-MM-dd HH:mm:ss') 

addToTime

Adds an integer number of a specified unit of time to a string timestamp passed in.

Syntax

addToTime(timestamp, interval, timeUnit, format?)

Possible intervals:

  • Second
  • Minute
  • Hour
  • Day
  • Week
  • Month or Year
  • Year

Example

// add 5 hours to now
addToTime(utcNow(),5,'Hour','yyyy-MM-dd HH:mm:ss')
addtotime power automate
addToTime Power Automate

Learn more about the Power Automate addToTime function!

convertFromUtc

Converts a string timestamp passed in from a UTC to a target time zone.

Syntax

convertFromUtc(timestamp, destinationTimeZone, format?)

Take a look at the list of timezones to find the timezone you need.

Example

convertFromUtc(utcNow(), 'Central Standard Time (Mexico)')

convertFromUtc(utcNow(), 'Pacific Standard Time','yyyy-MM-dd HH:mm:ss')

Learn more about the Power Automate convertFromUtc function!

convertTimeZone

Converts a string timestamp passed in from a source time zone to a target time zone.

Syntax

convertTimeZone(timestamp, sourceTimeZone, destinationTimeZone, format?)

Take a look at the list of timezones to find the timezone you need.

Example

convertTimeZone(utcNow(), 'W. Europe Standard Time','Pacific Standard Time','yyyy-MM-dd HH:mm:ss')

Learn more about the Power Automate convertTimeZone function!

convertToUtc

Converts a string timestamp passed in from a source time zone to UTC.

Take a look at the list of timezones to find the timezone you need.

Syntax

convertToUtc(timestamp, sourceTimeZone, format?)

Example

convertToUtc('2022-10-12 10:22:11','Pacific Standard Time','g')

Learn more about the Power Automate convertToUtc function!

dayOfMonth

Returns the day of month component of a string timestamp.

Syntax

dayOfMonth(timestamp)

Example

// Returns the day of month, for instance for the 15th mai it would be: 15
dayOfMonth(utcNow())

dayOfWeek

Returns the day of week component of a string timestamp.

Syntax

dayOfWeek(timestamp)

Example

// Returns for instance '2' for Tuesday
dayOfWeek(utcNow())

dayOfYear

Returns the day of year component of a string timestamp.

Syntax

dayOfYear(timestamp)

Example

// Example returns '1'
dayOfYear(convertToUtc('2022-01-01 10:22:11','Pacific Standard Time','g'))

formatDateTime

Returns a string in date format.

Use the Locale to change date language.

Syntax

formatDateTime(timestamp, format?, locale?)

Take a look at the list of locales to find the locale you need.

Example

// as an example, the result could be '2022-03-15'
formatDateTime(utcNow(),'yyyy-MM-dd')

// With locale returns 'martes enero 18'
formatDateTime('01/18/2022', 'dddd MMMM d', 'es-es')

Learn more about the Power Automate formatDateTime function!

getFutureTime

Returns a timestamp that is the current time plus the specified time interval.

Syntax

getFutureTime(interval, timeUnit, format?)

Possible intervals:

  • Second
  • Minute
  • Hour
  • Day
  • Week
  • Month or Year
  • Year

Example

// get time 5 hours from now
getFutureTime(5,'Hour','yyyy-MM-dd HH:mm:ss')
get future time power automate
get future time Power Automate

getPastTime

Returns a timestamp that is the current time minus the specified time interval.

Syntax

getPastTime(interval, timeUnit, format?)

Possible intervals:

  • Second
  • Minute
  • Hour
  • Day
  • Week
  • Month or Year

Example

// get time 5 hours before now
getPastTime(5,'Hour','yyyy-MM-dd HH:mm:ss')

parseDateTime

Converts a string, with optionally a locale and a format to a date.

Syntax

parseDateTime(dateString, locale?, format?)

Take a look at the list of locales to find the locale you need.

Example

// Returns '2022-01-18T00:00:00.0000000' 
parseDateTime(formatDateTime('01/18/2022', 'dddd MMMM d', 'es-es'), 'es-es','dddd MMMM d')
parsedatetime power automate
parseDateTime Power Automate

Learn more about the Power Automate parseDateTime function!

startOfDay

Returns the start of the day to a string timestamp passed in.

Syntax

startOfDay(timestamp, format)

Example

// As an example might return '2022-03-15 00:00:00'
startOfDay(utcNow(), 'yyyy-MM-dd HH:mm:ss')

startOfHour

Returns the start of the hour to a string timestamp passed in.

Syntax

startOfHour(timestamp, format)

Example

// As an example might return '08:00:00'
startOfHour(utcNow(), 'HH:mm:ss')

startOfMonth

Returns the start of the month of a string timestamp.

Syntax

startOfMonth(timestamp, format)

Example

// As an example might return '2022-03-01'
startOfMonth(utcNow(), 'yyyy-MM-dd')

More on the startOfMonth function and how to calculate the end of the month in the article: How To Get Start And End Of The Month In Power Automate

subtractFromTime

Subtracts an integer number of a specified unit of time from a string timestamp passed in.

Syntax

subtractFromTime(timestamp, interval, timeUnit, format?)

Example

// subtract 5 hours from now
subtractFromTime(utcNow(),5,'Hour','yyyy-MM-dd HH:mm:ss')
subtractfromtime power automate
subtractFromTime Power Automate

Learn more about the Power Automate subtractFromTime function!

ticks

Returns the number of ticks (100 nanoseconds interval) since 1 January 0001 00:00:00 UT of a string timestamp.

This converts time to integer.

Syntax

ticks(timestamp)

Example

// As an example might return '637829284109642706'
ticks(utcNow())

utcNow

Returns the current timestamp as a string.

Syntax

utcNow()

Example

power automate utcnow example
utcNow()
power automate utcnow example result
Result utcNow()
// utcNow with format; example: 2022-03-12 11:58:58
utcNow('yyyy-MM-dd HH:mm:ss')

Hint: More on the utcNow function.

Actions

Power Automate offers a couple of date and time related actions. To help you to understand which actions exist and how they can be used, we provided examples and short explainations for every date or time related function.

Note: For all the actions explained below, there is a function that can be used instead. So what to prefer when? I tend to prefer functions to actions because the resulting flow is smaller. Actions are easier to use and to understand. In small flows or when the date operation is important to understand, I would use actions. For everything else I would prefer functions.

Add to time

Adds a time span to a specified time.

Example

This example adds 1 day to the current date time.

Power Automate Add To Time Action
Add one day to now
Power Automate Add To Time Action Result 1
Result: One day added from 8th march to 9th march

Convert time zone

Converts a time to a specified target time zone.

Example

Power Automate Convert time zone Action
Convert time zone action: UTC+01:00 to UTC-06:00
Power Automate Convert time zone Action Result
Result Convert time zone action

Current time

Gets the current time in UTC.

Example

Power Automate Current Time Action
Current time action
Power Automate Current Time Action Result
Current time action result

Get future time

Returns a timestamp that is the current time plus the specified time interval.

Example

Power Automate Get future time Action
Get future time action: add 25 minutes to now
Power Automate Get future time Action Result
Result with added 25 minutes to now

Get past time

Returns a timestamp that is the current time minus the specified time interval.

Example

Power Automate Get past time Action
Get past time action: subtract 12 month from now
Power Automate Get past time Action Result
Result with subtracted 12 month from now

Subtract from time

Subtracts a time span from a specified time.

Power Automate Subtract From Time Action
Subtract one month from now
Power Automate Subtract From Time Action Result
Result: One month subtracted from March to February

FAQ – Power Automate Date and Time

How to create a date variable in Power Automate?

Power Automate Date Variable

There is no dedicated data type for date, time or datetime. You have to work with strings.

How to format date time for 24 hours in Power Automate?

Use two uppercase H like this for instance for the current UTC time:

utcNow(‘HH:mm’)

How to add years to a date in Power Automate?

Use addToTime with Year interval. Example one year from now:

addToTime(utcNow(),1,’Year’,’yyyy-MM-dd HH:mm:ss’)

How to calculate the time difference between two dates?

1: Use the ticks expression to convert the date to a integer.
2: Use sub to calculate the difference.
3: Divide the result to get the time interval you need. See example for minutes past since the beginning of the hour:

div(sub(ticks(utcNow()),ticks(startOfHour(utcNow()))),600000000)

How to get the week number from a date?

You can find out the week number of the current date by this (adapt to your needs):

add(div(dayOfYear(utcNow()),7),1)

2 thoughts on “Power Automate Date & Time Formatting, Functions, Actions”

  1. Thank you for these examples. For some reason, it is really hard to find these anywhere on the internetz!

Leave a Comment

Your email address will not be published. Required fields are marked *