Home > Software engineering >  How to pass next month date using utcnow in adf expression
How to pass next month date using utcnow in adf expression

Time:11-01

I am using the below expression in the copy data activity to append current month and year to the filename. I want to pass next month date to the filename(testingfile1220222)

ex:testingfile112022(current month 11 and year 2022)

expected: testingfile122022(next month 12 and year 2022)

@concat(pipeline().parameters.pipelinepath,'testingfile',formatDateTime(utcNow(),'MM'),formatDateTime(utcNow(),'yyyy'),'.csv'')/$value/')

CodePudding user response:

I have used the following dynamic content to build a name for my sample file. It has given the expected output of testingfile122022.csv.

  • I have used mathematical functions to create dynamic file name. If the month is already equal to 12, adding one would result in month number as 13. So, to avoid this, I have taken the if condition to avoid this.
@concat('testingfile',if(equals(12,int(formatDateTime(utcNow(),'MM'))),'01',string(add(int(formatDateTime(utcNow(),'MM')),1))),formatDateTime(utcNow(),'yyyy'),'.csv')

enter image description here

  • The pipeline run is successful. It writes a file with the required name. Look at the following image for reference.

enter image description here

  • You can also use the getFutureTime as suggested by @Scott Mildenberger using the following dynamic content.
@concat('testingfile',formatDateTime(getFutureTime(1,'Month'),'MM'),formatDateTime(utcNow(),'yyyy'),'.csv')

NOTE: I have run this on 1/11/2022.

  • Related