First day Of this week and last week

后端 未结 3 1357
梦毁少年i
梦毁少年i 2021-02-06 16:42

I am currently getting first day Of this week and last week values with vbscript function in 2/12/2009 format. I was wondering if it was possible with SQL query.

3条回答
  •  春和景丽
    2021-02-06 17:46

    These statements should do what you want in TSQL. Note, the statements are based on the current date. You can replace getdate() for whatever date you wish:

    Select dateadd(wk, datediff(wk, 0, getdate()) - 1, 0) as LastWeekStart
    Select dateadd(wk, datediff(wk, 0, getdate()), 0) as ThisWeekStart
    Select dateadd(wk, datediff(wk, 0, getdate()) + 1, 0) as NextWeekStart
    

    There are lots of other date routines here.

提交回复
热议问题