Date and Time Functions in Power Automate
π Mastering Date and Time Functions in Power Automate
Date and time functions in Power Automate are essential for building intelligent flows that depend on time-based logic. Whether youβre scheduling tasks, formatting timestamps, or calculating durations, these functions help you handle temporal data with precision and flexibility.
From sending reminders to organizing documents by date, mastering date and time functions in Power Automate ensures your flows behave predictably and dynamically.
Why Date and Time Handling Matters in Flows
Working with time in automation is crucial when:
- Logging events
- Scheduling emails or reminders
- Generating file names with timestamps
- Filtering records by date
- Comparing time-based conditions
- Monitoring SLAs or due dates
Without accurate date formatting and manipulation, flows may break, send data to the wrong place, or calculate incorrect results.
π Real-World Use Cases for Date and Time Functions
Use Case | Description |
---|---|
Generate a report file name with the current date | e.g., SalesReport_20250807.pdf |
Send birthday emails | Compare todayβs date with stored birth dates |
Filter SharePoint or Dataverse records | Retrieve items created in the past 7 days |
Calculate time differences | Measure duration between submission and approval |
Set reminders | Use delay/until based on dynamic date values |
π§ Date and Time Functions in Power Automate
Below is a detailed table of common date and time functions in Power Automate with syntax, purpose, and example output.
Function | Purpose | Syntax | Example | Output |
---|---|---|---|---|
utcNow() |
Returns current UTC time | utcNow() |
2025-08-07T14:00:00Z |
Current time |
addDays() |
Adds days to a date | addDays(utcNow(), 5) |
2025-08-12 |
5 days later |
addHours() |
Adds hours to a date | addHours(utcNow(), 3) |
2025-08-07T17:00:00Z |
3 hours later |
subDays() |
Subtracts days | subDays(utcNow(), 7) |
2025-07-31 |
1 week ago |
formatDateTime() |
Formats a date | formatDateTime(utcNow(), 'yyyy-MM-dd') |
2025-08-07 |
ISO format |
convertTimeZone() |
Converts time zones | convertTimeZone(utcNow(), 'UTC', 'Pacific Standard Time') |
2025-08-07T07:00:00-07:00 |
|
ticks() |
Returns a timestamp in ticks | ticks(utcNow()) |
637949184000000000 |
|
dateTimeAdd() |
Adds a time span | addDays(utcNow(), 1) |
Tomorrow's date |
|
dayOfWeek() |
Returns day index (0=Sunday) | dayOfWeek(utcNow()) |
4 (for Thursday) |
π§ͺ Practical Examples of Date and Time Functions
1. Generate Timestamped File Name
concat('Invoice_', formatDateTime(utcNow(), 'yyyyMMdd'), '.pdf')
Output: Invoice_20250807.pdf
2. Send Notification 2 Days Before Due Date
addDays(triggerOutputs()?['DueDate'], -2)
Use Case: Compare this with utcNow()
and trigger reminder.
3. Convert UTC Time to Local Time
convertTimeZone(utcNow(), 'UTC', 'Eastern Standard Time')
Output: Local time in Eastern zone.
4. Check if Today is a Userβs Birthday
formatDateTime(utcNow(), 'MM-dd') == formatDateTime(triggerBody()?['DOB'], 'MM-dd')
Use Case: Sends birthday wishes if dates match.
5. Calculate Number of Days Between Two Dates
div(sub(ticks('2025-08-10T00:00:00Z'), ticks('2025-08-01T00:00:00Z')), 864000000000)
Output: 9
(days between August 1 and August 10)
π§ Best Practices for Date and Time in Power Automate
- β
Always format your dates using
formatDateTime()
for consistency in comparisons and naming. - β
Use
convertTimeZone()
to adjust from UTC to local time for user-facing content. - β
Avoid hardcoded datesβuse
utcNow()
andaddDays()
to calculate relative values. - β Compare formatted dates, not raw UTC timestamps, to avoid mismatches.
- β Use ticks and math for accurate date/time difference calculations.
- β Check time zones in your environment and apply accordingly to avoid errors in scheduling.
β οΈ Common Pitfalls and How to Avoid Them
Problem | Cause | Fix |
---|---|---|
Wrong time zone | utcNow() returns UTC |
Use convertTimeZone() |
Date comparison fails | Format mismatch | Use formatDateTime() for consistent format |
Incorrect future/past math | Misused addDays() or subDays() |
Check signs (+/-) carefully |
Ticks conversion confusion | Large tick values | Always divide by 864000000000 to get days |
Local vs UTC issues | UI shows local but flow uses UTC | Display converted local time in messages |