How to compare two dates in ADF to see which is greater?

Mike Langlois 15 Reputation points
2024-05-30T12:03:14.8966667+00:00

Hi there,

I am using Azure Data Factory to compare two dates (one is stored in a string variable and one its utcnow) and I need to know when the utcnow is greater than the date in the stored string variable. Both are just dates no timestamps

I looked at the logical function 'greater' (and 'less') but it seems that doesnt work with dates?

Assuming I am being blind and missing an obvious function that does it, how do you compare two dates in ADF to see which is greater?

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,646 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Smaran Thoomu 24,260 Reputation points Microsoft External Staff Moderator
    2024-05-30T12:28:20.7866667+00:00

    Hi @Mike Langlois
    Thanks for the question and using MS Q&A platform.

    To compare two dates in ADF to see which is greater, you can use the greaterOrEquals function. This function compares two dates and returns true if the first date is greater than or equal to the second date. Here's an example of how to use this function:

    @greaterOrEquals(string(variables('date1')), string(variables('date2')))
    

    In this example, date1 is the string variable that stores the first date, and date2 is the current UTC date obtained using the utcNow() function. The string() function is used to convert the dates to string format, which is required for the greaterOrEquals function to work.

    If you want to check if the first date is strictly greater than the second date, you can use the greater function instead:

    @greater(string(variables('date1')), string(variables('date2')))
    

    Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.