Errors adding a day to a date in ADF script

Yi Han Wong 40 Reputation points
2025-05-15T18:59:44.0833333+00:00

I'm having an issue where I'm trying to add a day to a start date parameter, this is the script I used in the Script activity within ADF:

@concat('SELECT DATEADD(dd, 1, CONVERT(DATETIME, ''',variables('v_POLLED_DT'), '''))')

However I'm getting the following error message:

Failed to execute script. Exception: ''Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=Failed to execute the query command during read operation.,Source=Microsoft.DataTransfer.Execution.ScriptActivityExecutor,''Type=Apache.Arrow.Adbc.C.CAdbcDriverImporter+ImportedAdbcException,Message=[Snowflake] 000904 (42000): SQL compilation error: error line 1 at position 30 invalid identifier 'DATETIME',Source=Apache.Arrow.Adbc,''

Am I missing something here, as I'm pretty sure this is a valid T-SQL statement?

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

Accepted answer
  1. Nandan Hegde 36,066 Reputation points MVP Volunteer Moderator
    2025-05-16T04:55:39.51+00:00

    As the system is Snowflake, plz leverage the below syntaxes :

    @concat('SELECT DATEADD(''day'', 1, TO_DATE(''', variables('v_POLLED_DT'), '''))')

    or

    SELECT DATEADD('day', 1, TO_DATE(@{variable}))

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Ganesh Gurram 7,140 Reputation points Microsoft External Staff Moderator
    2025-05-15T22:02:24.95+00:00

    @Yi Han Wong

    The error occurs because you're using T-SQL functions (CONVERT and DATETIME) which are not supported in Snowflake. Snowflake uses a different SQL dialect, and the function CONVERT(DATETIME, …) is invalid there.

    To add a day to a date in Snowflake, you should use the DATEADD function with a valid date conversion function like TO_TIMESTAMP. Here's how you can rewrite your script for the Script activity in Azure Data Factory:

    
    @concat('SELECT DATEADD(DAY, 1, TO_TIMESTAMP(\'', variables('v_POLLED_DT'), '\'))')
    

    Reference:

    These functions are the correct way to handle date arithmetic and conversion in Snowflake.

    I hope this information helps.

    Kindly consider upvoting the comment if the information provided is helpful. This can assist other community members in resolving similar issues.

    0 comments No comments

  2. Yi Han Wong 40 Reputation points
    2025-05-16T12:31:10.1233333+00:00

    I managed to fix the issue, it turns out the Until activity works by looping continuously until the condition is met, rather than using variable less than or equal to EndDate, I just need to change it to variable greater than EndDate and it worked

    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.