Compare today with some value passed from front end
I need to compare current day with some value. Like from front end开发者_运维问答 I am passing 5
, then in t-sql
I want to match if the current day of the month is 5
.
You can retrieve parts of the date with DATEPART.
DATEPART ( datepart , date )
DATEPART( MM, GETDATE())
Should return an INT
value of 3
for March
.
Well, just pass an INT
parameter to your stored procedure (I'm assuming you're using this in a stored procedure?). Then you can do something like
IF DATEPART(dd, CURRENT_TIMESTAMP) = @givenday ...
Does that help?
精彩评论