Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 38 ยท Actions and Expressions

Text, Dates and Time Zones in Power Automate Expressions

Work with strings and dates in flows: concat, substring, replace, split, formatDateTime, addDays, convertTimeZone, utcNow and format strings, with runnable stand-ins.

Most flow bugs involve text and dates: a file name that contains a forbidden character, a date that shows the wrong day, a "today" that is yesterday in another time zone. This lesson collects the functions you need.

Text functions

Function Example Result
concat(a, b, ...) concat('INV-', '1042') INV-1042
substring(text, start, length) substring('Invoice', 0, 3) Inv
replace(text, old, new) replace('a-b-c', '-', '_') a_b_c
split(text, sep) split('a,b,c', ',') ['a','b','c']
join(array, sep) join(createArray('a','b'), '; ') a; b
toLower / toUpper toUpper('abc') ABC
trim(text) trim(' hi ') hi
length(text) length('hello') 5
indexOf(text, find) indexOf('hello','l') 2
startsWith / endsWith endsWith('a.pdf','.pdf') true
slice(text, start, end) slice('abcdef', 1, 4) bcd

String positions start at 0. substring raises an error if start + length runs past the end, so check length first or use slice, which is more forgiving about the end index.

You can also embed values into text with @{...}: File @{variables('name')}.pdf.

Cleaning a file name

SharePoint and OneDrive reject characters such as \ / : * ? " < > | and # and % in names. Replace them before you save a file.

Python Stand-in: clean a file name like chained replace() calls

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In a flow you nest replace calls or put the characters in a Compose and loop. The idea is the same.

Dates and times

Dates are text in ISO 8601 form, such as 2025-03-14T09:30:00Z. The Z means UTC. Key functions:

Function Example Meaning
utcNow() utcNow() Current time in UTC
utcNow('yyyy-MM-dd') Formatted current time
addDays(ts, n) addDays(utcNow(), 7) Plus 7 days (negative for past)
addHours, addMinutes, addToTime Other units
formatDateTime(ts, fmt) formatDateTime(utcNow(), 'dd/MM/yyyy') Change format
convertTimeZone(ts, from, to, fmt) convertTimeZone(utcNow(), 'UTC', 'W. Europe Standard Time', 'HH:mm') Change zone
convertFromUtc(ts, tz, fmt) / convertToUtc Same idea in one direction
startOfDay, startOfMonth, startOfHour Truncate
dayOfWeek(ts) 0 is Sunday
ticks(ts) 100 ns units since year 0001
dateDifference(start, end) Duration as d.hh:mm:ss

Format strings

Common tokens: yyyy year, MM month (capital), dd day, HH 24-hour, hh 12-hour, mm minutes (lowercase), ss seconds, tt AM/PM, dddd weekday name, MMMM month name.

Mixing up MM (month) and mm (minute) is the classic error: yyyy-mm-dd gives a minute where the month should be.

Python Stand-in: date format tokens in Python

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The Python tokens differ (%Y instead of yyyy), but the thinking is identical.

Time zones

utcNow() is always UTC. A flow that runs at 23:30 in New York already sees tomorrow's date in UTC. Convert before you use a date that a person will read or compare.

Use Windows time zone names, such as Pacific Standard Time, Eastern Standard Time, W. Europe Standard Time, India Standard Time, Tokyo Standard Time. They already handle daylight saving.

TEXT
convertTimeZone(utcNow(), 'UTC', 'Eastern Standard Time', 'yyyy-MM-dd')
convertFromUtc(utcNow(), 'Tokyo Standard Time', 'dd MMM yyyy HH:mm')

This stand-in uses fixed offsets (a real flow uses zone names, which handle daylight saving for you) to show how the same instant gives different dates.

Python Stand-in: one instant, two dates

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Common date tasks

  • Due date in 14 days: addDays(utcNow(), 14, 'yyyy-MM-dd') (addDays accepts a format as the third argument).
  • Start of this month: startOfMonth(utcNow(), 'yyyy-MM-dd').
  • Is it a weekend? or(equals(dayOfWeek(utcNow()), 0), equals(dayOfWeek(utcNow()), 6)).
  • Days between two dates: div(sub(ticks(end), ticks(start)), 864000000000).
  • Compare dates: compare ISO strings with greater and less: ISO strings sort correctly as text if they have the same format and zone.

Common mistakes

  • mm for month.
  • Reading a Dataverse or SharePoint date as local time when it is UTC.
  • Using substring past the end of a short string.
  • Comparing a formatted date such as 14/03/2025 as text; use ISO format for comparisons.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which format string gives a date like 2025-03-14?

    MM is the month and mm is minutes, so yyyy-MM-dd gives year-month-day.
  2. 2. What does utcNow() return?

    utcNow() always returns UTC; convert for local display.
  3. 3. Which function changes a timestamp from UTC to Tokyo Standard Time?

    convertTimeZone and convertFromUtc change the zone using Windows time zone names.
  4. 4. What does substring('Invoice', 0, 3) return?

    substring starts at index 0 and takes three characters.

Summary

  • Text functions: concat, substring, replace, split, join, trim, toLower, startsWith.
  • Dates are ISO strings; use formatDateTime, addDays and convertTimeZone, and mind MM versus mm.
  • utcNow() is UTC, so convert before showing dates to people.
  • Clean file names and compare dates in ISO format.

Next: Arrays, objects and JSON