用户登录
用户注册

分享至

如何使用 SQL Server 与当前周进行比较?

  • 作者: 生人也若初见
  • 来源: 51数据库
  • 2022-12-01

问题描述

如何将 SQL Server 日期列与当前周进行比较?

How do I compare an SQL Server date column against the current week?

例如:

WHERE [Order].SubmittedDate = *THIS WEEK*

推荐答案

您可以将日期转换为周数,并将其与当前日期的周数进行比较.同样,您还需要比较年份,以免获得去年的周数.

You could convert your date to a week number and compare this to the week number from the current date. Likewise, you'll need to compare the year as well, so that you don't get last year's weeks.

WHERE DATEPART(wk, [Order].SubmittedDate) = DATEPART(wk, GETDATE())
AND DATEPART(yy, [Order].SubmittedDate) = DATEPART(yy, GETDATE())
软件
前端设计
程序设计
Java相关