DATEADD function equivalent in Azure Data Factory

Jonathan Holén 10 Reputation points
2023-07-13T10:28:50.06+00:00

I have a SQL DATEADD statement that I'm trying to replicate in Azure Data Factory (ADF), specifically within a data flow using a derived column. My SQL code looks like this:

DATEADD(SECOND,[TripHours] * 60.0 * 60.0,[TripTimeStamp])

I tried to convert this logic into ADF syntax in the following way:

add(TripTimeStamp, toInteger(multiply(TripHours, 60 * 60)))

The TripTimeStamp column is of type DateTime and TripHours is a float type. However, my ADF solution only seems to add a couple of minutes to the TripTimeStamp column, not the expected number of hours.

The column names are changed for privacy. But this is an example.

TripTimeStampTripHoursExpected ResultActual Result2021-03-10 07:54:00.00022,12021-03-11 06:00:00.0002021-03-10 07:55:19.560 Any advice on what i might be doing wrong?

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

1 answer

Sort by: Most helpful
  1. Jonathan Holén 10 Reputation points
    2023-07-13T10:40:31.7666667+00:00

    Wow, okay typical that i solved it just after posting.

    So in the original SQL code, i was adding seconds.

    
    DATEADD(SECOND,[TripHours] * 60.0 * 60.0,[TripTimeStamp])
    
    

    However, Azure Data Factory's 'add' function interprets time in milliseconds, not seconds. So, to get the same result in Azure Data Factory, I had to adjust the original query to convert the time to milliseconds:

    
    add(TripTimeStamp, toInteger(multiply(TripHours, 60 * 60 * 1000)))
    
    
    2 people found this answer helpful.

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.