Date Parameter

Rohit Kulkarni 676 Reputation points

Hello Team,

I have applied the below mentioned date parameter but i am getting error mentioned below:

And need to pass the dynmic date like

from Date : 01-Feb-2022(FirstDayof Current Month)
To Date : 01-Mar-2022 (FirstDayof NextMonth)

declare @StartDate datetime = 'CAST(DATEADD(DAY,-DAY(GETDATE())+1, CAST(GETDATE() AS DATE)) AS DATE)'
declare @EndDate datetime = 'DATEADD(d, 1, EOMONTH(current_timestamp))'


A database operation failed with the following error: 'Conversion failed when converting date and/or time from character string.'
Conversion failed when converting date and/or time from character string., SqlErrorNumber=241,Class=16,State=1,
Activity ID: cab3a5b7-b9e9-46b1-8de5-02c12f18461b

Please advise .


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

Accepted answer
  1. AnnuKumari-MSFT 30,361 Reputation points Microsoft Employee

    Hi @Rohit Kulkarni ,
    Thankyou for using Microsoft Q&A platform and posting your question.
    While declaring variables you have kept the expression inside single quotes which is causing the error.
    Could you please try replacing the two lines of codes with the following:

    declare @StartDate datetime = CAST(DATEADD(DAY,-DAY(GETDATE())+1, CAST(GETDATE() AS DATE)) AS DATE)
    declare @EndDate datetime = DATEADD(d, 1, EOMONTH(current_timestamp))

    Hope this will help. Please let us know if any further queries.


    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you.
      Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful