Reputation: 37
i am trying to pass first day and last day of previous month as a date parameter in my stored procedure but it's throwing data conversion error like below:
Conversion failed when converting date and/or time from character string.
Here's example how i passed the parameter;
EXEC DBO.usp_PRODUCTS 'DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 1, 0)'
,'DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), -1)'
The data type for start date and end date in my stored proc is date , even if i change to varchar, it's showing similar error.
Is there any way i can pass first day and last day of previous month as parameter in my stored proc?
Upvotes: 0
Views: 2681
Reputation: 966
Try this
Declare @startDate Date = DATEADD(month, DATEDIFF(month,0,GETDATE())- 1, 0);
Declare @endDate Date = DATEADD(month, DATEDIFF(month,0,GETDATE()) , 0);
EXEC DBO.usp_PRODUCTS @startDate , @endDate ;
Upvotes: 1