如何获取SQL Server 2008中当前周的开始日期?

时间:2022-04-01 01:43:14

using: SQL Server 2008r2 via: aspx HTML page

使用:SQL Server 2008r2 via:aspx HTML页面

I need to find the start date for the current week. It does not matter if it gives me Sunday's date or Monday's date, but I need to be able to find all transactions this week, for example.

我需要找到当周的开始日期。如果它给我星期日的日期或星期一的日期并不重要,但我需要能够找到本周的所有交易,例如。

Also, if someone can point me to a page that explains all the Date functions in SQL2008 that would be splendid too!

此外,如果有人可以指向一个解释SQL2008中所有日期功能的页面,那也很精彩!

I searched around and found not much that was applicable (either I didn't search with the right keywords or there literally is no-one who has asked this before!)

我四处搜索,发现没有太多适用的(我没有使用正确的关键字进行搜索,或者之前没有人问过这个问题!)

1 个解决方案

#1


3  

A combination of dateadd and datediff will accomplish this.

dateadd和datediff的组合将实现这一目标。

select dateadd(wk, datediff(wk, 0, getdate()), 0)

Note that wk is the abbreviation for the week datepart parameter in dateadd.

请注意,wk是dateadd中week datepart参数的缩写。

This MSDN page clearly and comprehensively explains the Date (and Time) methods in SQL 2008 R2.

此MSDN页面清楚而全面地解释了SQL 2008 R2中的日期(和时间)方法。

#1


3  

A combination of dateadd and datediff will accomplish this.

dateadd和datediff的组合将实现这一目标。

select dateadd(wk, datediff(wk, 0, getdate()), 0)

Note that wk is the abbreviation for the week datepart parameter in dateadd.

请注意,wk是dateadd中week datepart参数的缩写。

This MSDN page clearly and comprehensively explains the Date (and Time) methods in SQL 2008 R2.

此MSDN页面清楚而全面地解释了SQL 2008 R2中的日期(和时间)方法。