How to use formatDateTime in Azure Data Factory?

Viewed 11182

I would like to format the pipeline trigger time in this format:

10-Mar-2021 08:31:59 AM

Here is the code I am using:

@formatDateTime(pipeline().TriggerTime, 'DD-MON-YYYY HH:MI:SS AM/PM')

However the date is coming out in this format:

'DD-3ON-YYYY 08:3I:SS A3/P3'

Can anyone please help me out in resolving this?

2 Answers

The formatDateTime function uses the custom date format strings which you can see listed here. A detailed breakdown

dd - the day of the month from 01 to 31.  Note this is lower case and this format gives a leading 0.  Using d for no leading 0
MMM - the abbreviated name of the month, eg JAN, FEB, MAR.  Note this is upper case
yyyy - the year as a four-digit number.  Note this is lower case
hh - the hour using a 12-hour clock from 01 to 12.  Note this is lower case.  As you are using AM/PM it makes sense to have the 12-hour clock rather than 24 (ie 23:00 PM would not make sense).  Note this is lower case
mm - the minute from 00 to 50.  Note this is lower case
ss - the second from 00 to 50.  Note this is lower case
tt - the AM/PM designator.  Note this is lower case

So using this information, your code should be more like this:

@formatDateTime(pipeline().TriggerTime, 'dd-MMM-yyyy hh:mm:ss tt')

I have test the expression using a Set Variable activity and got the following results:

ADF result

EEE : Day ( Mon ) MMM : Month in words ( Dec ) MM : Day in Count ( 324 ) mm : Month ( 12 ) dd : Date ( 3 ) HH : Hours ( 12 ) mm : Minutes ( 50 ) ss : Seconds ( 34 ) yyyy: Year ( 2020 ) //both yyyy and YYYY are same YYYY: Year ( 2020 ) zzz : GMT+05:30 aa : ( AM / PM )

Related