How to get current date in logic app | How to format date time in Logic App

{tocify} $title={Table of Contents}



Many times in the workflow we need to get the current time and use it.


One very common scenario is using current time to append it with FileName or blob name to make it unique.

In logic app there are sets of out of box functions available which we can use as per our need.


How to get current date in logic app


Simplest way is to Initialize a variable , give it a name , select the type as String (Date/DateTime type is not available) and against value - go to Expression--> Select utcNow()




How to get current date in logic app



Below is what you get as output, the default format.

Output of get current date in Logic App

Note : utcNow('<format>') returns date in string . 

Optionally, you can specify a different format with the <format> parameter.

yyyy = Year (2022)
MM = Month (05)
dd = Day (01)
HH = Hour (15)
mm = Minute (41)
ss = Second (15)


Apart from utcNow() function  other datetime functions can be used to work with dates and times. Date and time functions available are:

startOfDay – Return the start of the day for a timestamp.
startOfHour – Return the start of the hour for a timestamp.
startOfMonth – Return the start of the month for a timestamp
addDays – Add several days to a timestamp.
addHours – Add several hours to a timestamp.
addMinutes – Add several minutes to a timestamp.
addSeconds – Add several seconds to a timestamp.
addToTime – Add several time units to a timestamp.
convertFromUtc – Convert a timestamp from Universal Time Coordinated (UTC) to the target time zone.
convertTimeZone – Convert a timestamp from the source time zone to the target time zone.
convertToUtc – Convert a timestamp from the source time zone to Universal Time Coordinated (UTC).
getFutureTime – Return the current timestamp plus the specified time units
getPastTime – Return the current timestamp minus the specified time units.
dayOfMonth – Return the day of the month component from a timestamp.
dayOfWeek – Return the day of the week component from a timestamp.
dayOfYear – Return the day of the year component from a timestamp.
subtractFromTime – Subtract several time units from a timestamp.
ticks – Return the ticks property value for a specified timestamp
formatDateTime – Return the date from a timestamp.


How to format date time in Logic App

Below is an example of using formatDateTime to format date time 


        formatDateTime(utcNow(), 'yyyy-MM-ddTHH:mm:ss')

Here we are providing current system time using utcNow() function, and want it to be in following format 'yyyy-MM-ddTHH:mm:ss'

Following is the output :    2022-06-21T08:47:19






If you have questions or suggestions, feel free to do in comments section below !!!


Do share if you find this helpful .......
 
                        Knowledge Sharing is Caring !!!!!!


 


Learn More about Logic App

Post a Comment

If you have any suggestions or questions or want to share something then please drop a comment

Previous Post Next Post