gabi
gabi

Reputation: 1376

Azure: Compare dates in Data factory

Data factory doesn't have a built-in date difference function. I want to compare lastModified date and utcnow in if condition activity. How can I achieve it?

@greaterOrEquals(activity('Get Metadata1').output.lastModified, '2015-03-15T13:27:36Z')

Upvotes: 9

Views: 16079

Answers (4)

madhu chilukuri
madhu chilukuri

Reputation: 31

we can get date difference count between 2 dates. @string(div(div(div(div(sub(ticks(variables('presentdate')),ticks(variables('pastdate'))),10000000),60),60),24))

Upvotes: 2

Daniel Ford
Daniel Ford

Reputation: 71

I had this problem today where I needed a check to see whether the utcNow() time was greater than 2AM (inside an if block in the Data Factory).

On the above advice, I used the ticks() function. I'm sure its not the most elegant but wasn't sure how to convert the hour section of the datetimes nicely as it seemed that hour() wasnt supported.

@if(greaterOrEquals(div(sub(ticks(utcNow()),ticks(startOfDay(utcNow()))),36000000000),2))True,False)

with the 36,000,000,000 division converting the 100ns ticks into the number of hours between the utcNow() and the startOfday(utcNow())

Upvotes: 2

Fang Liu
Fang Liu

Reputation: 2361

You can use the ticks function to convert it to integer. Logic Apps function reference for Ticks

The ADF UI may show a warning about it not being a recognized function, but ADF is actually using logic app expressions so it will succeed if you debug or trigger the pipeline.

Upvotes: 8

gabi
gabi

Reputation: 1376

I solved it by converting year and month part of dates to integers and comparing them.

Upvotes: 1

Related Questions