John
John

Reputation: 13

Dynamic StartDate and Todays Date in SQL

I have a Stored Procedure that takes Start Date and End Dates. So the Start Date must start from 1/1/2018. I want to make the Start Date as Dynamic- meaning when we are in 2019, the start Date will pick up 1/1/2019 and End Date is always Today's date. I appreciate for any help.

StartDate: 1/1/2018
EndDate: TodaysDate

Thanks

Upvotes: 1

Views: 250

Answers (1)

Pranay Rana
Pranay Rana

Reputation: 176956

you can get it in sql itself like this

SELECT
   DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0) AS StartOfYear,
   GETDATE() AS Today

Upvotes: 1

Related Questions