开发者

SQL to select records with a date greater than 40 days prior to start of month

I have a field in my table that holds a date and is in Datetime format.

I wish to select all records where the date in that field is greater than the date that is 40 days prior to the 1st of the current month.

Struggling to come开发者_如何学C up with the correct T-SQL syntax to do this.


This expression gives you the date you are looking for:

DATEADD(DAY, -DATEPART(d, GETDATE()) + 1 - 40, GETDATE())


Will this work

 select @urdatecolumn > (getdate()- (DAY(getdate()) + 40-1))


Try this

where dt_blah > DATEADD(d,-40,DATEADD(wk, DATEDIFF(wk, 0, dateadd(dd, 6 - datepart(day, dt_blah), dt_blah)), 0) 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜