A Quick Guide on using DateTime in Microsoft Flow

Adam Murchison, 08 August 2019

Microsoft Flow has many ways to set a DateTime and there are often strict requirements on how this is formatted for your purposes.

Firstly, the most important function to know within Microsoft Flow to do with DateTime is utcNow(). We can do this by going to the ‘Expression’ tab when adding data to an input, as shown below.

image

The function utcNow() returns a DateTime in the format of: 2019-07-25T21:48:02Z which is equivalent to: “yyyy-MM-ddTHH:mm:ssZ”.

We can reformat this in flow by doing the following:

image

The above example shows one way of formatting the date time to a date only. You can reformat this DateTime into any kind of format that you’re used to using in C#. If you’re unfamiliar with formatting DateTime as a string, then you can follow Microsoft’s documentation here.

The next thing that you will want to do is convert your DateTime from UTC to your Local Time. For example, my time zone is ‘New Zealand Standard Time’. The expression for this conversion is: convertFromUtc(utcNow(), 'New Zealand Standard Time', 'dd/MM/yyyy'). Note: the formatting ‘dd/MM/yyyy’ is optional but I added it in for sake of example.

If you wanted to send the time zone through to the Flow, then you should invoke it through a web request and pass it through as a parameter. To invoke a flow through a web request please see my other blog here. Also, see the below screenshot on how the ‘timeZone’ value used in my request to the flow appears inside the ‘convertFromUtc’ function:

image

image

In summary Microsoft Flow comes with many different useful features, DateTime is one of the features that require a bit of thought before going ahead and using them in your processes. Go ahead and try out the many cool things you can do with Flow.