SELECT GETDATE()
返回值: 2008-09-22 15:24:13.790
2008-09-22 15:24:13.790
我希望该日期部分没有时间部分: 2008-09-22 00:00:00.000
2008-09-22 00:00:00.000
我该怎么办?
以后SQL Server 2008,您应该CONVERT:
SQL Server 2008
CONVERT
SELECT CONVERT(date, getdate())
在旧版本上,您可以执行以下操作:
SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, @your_date))
例如
SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
给我
优点:
varchar
datetime
locale
正如迈克尔建议的
使用此变体: SELECT DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)
SELECT DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)
select getdate() SELECT DATEADD(hh, DATEDIFF(hh, 0, getdate()), 0) SELECT DATEADD(hh, 0, DATEDIFF(hh, 0, getdate())) SELECT DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0) SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, getdate())) SELECT DATEADD(mm, DATEDIFF(mm, 0, getdate()), 0) SELECT DATEADD(mm, 0, DATEDIFF(mm, 0, getdate())) SELECT DATEADD(yy, DATEDIFF(yy, 0, getdate()), 0) SELECT DATEADD(yy, 0, DATEDIFF(yy, 0, getdate()))
输出:
2019-04-19 08:09:35.557 2019-04-19 08:00:00.000 4763-02-17 00:00:00.000 2019-04-19 00:00:00.000 2019-04-19 00:00:00.000 2019-04-01 00:00:00.000 1903-12-03 00:00:00.000 2019-01-01 00:00:00.000 1900-04-30 00:00:00.000