SUMguy
SUMguy

Reputation: 1673

Get Yesterday's Date (MS Power Automate)

In Microsoft Power Automate, using the expression utcNow() you can get the current date (and time). I am trying to get yesterday's date. I tried dateadd(utcNow(), -1) and similar code, but nothing works. Anyone know how to work with dates in Microsoft Power Automate?

Upvotes: 4

Views: 31415

Answers (5)

Abhils
Abhils

Reputation: 363

You can use getPastTime(interval,TimeUnit,format?) function. It gives you the current time minus specified time interval. You can find this function in expression tab.

Here is the code for yesterday's date

getPastTime(1, 'Day', 'dd-MM-yyyy')

Where, second argument is Day, Month or Year, first argument is number and last argument is format of the date you want to achieve.

If today's date is "21/06/2023" then you will get "20-06-2023" as a result.

Upvotes: 1

SeaDude
SeaDude

Reputation: 4405

You can also use one of the newer built-in Date Time actions. Use Get past time and set it to 1 day interval to get yesterday:

enter image description here

Upvotes: 3

noobsterCoder
noobsterCoder

Reputation: 75

This code seems to work for me:

formatDateTime(addDays(utcNow(),-1),'MM.dd.yyyy')

I have used the dormatDateTime: function to get the date to change to format to what I want it to be

addDays: can be used to travel to and fro in dates like if I want to go back one day it will be -1 if I want it to go ahead one day it would be +1 or 1.

utcNow(): Gets me the current date and time

Now I can get the date in formats like "MM/dd/yyyy" or "MM.dd.yyyy" or "MM dd yyyy". This list of delimiters can be found here.

Upvotes: 5

Tomasz Ciarachowicz
Tomasz Ciarachowicz

Reputation: 11

You can use addDays():

addDays(utcNow(),-1)

Moreover you have addMinutes(), addHours(), addSeconds().

Upvotes: 1

AaronBaker
AaronBaker

Reputation: 1033

addDays is the function you're looking for:

//Yesterday
addDays(utcnow(),-1)

//Next Week
addDays(utcnow(),7)

Upvotes: 8

Related Questions