在 SQL 和查询中将日期转换为日期时间比
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9720992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert Date to DateTime in SQL and Query great than
提问by Wishn4fishn
I am having an issue with the most simple command in SQL Server Management. It seems the issue with is in the converting process. The current column is set to date only but I need to be able to specify the range under date and time. I would ultimately like to query where datetime is greater than the previous days datetime.
我在 SQL Server 管理中遇到了最简单的命令问题。似乎问题出在转换过程中。当前列仅设置为日期,但我需要能够指定日期和时间下的范围。我最终想查询日期时间在哪里大于前几天的日期时间。
Can anyone lend me a hand on this one? I am pulling may hair out on the most simple query.
谁能帮我看看这个?我正在对最简单的查询进行分析。
Select
FROM [CustomerTracking].[dbo].[Submission]
WHERE
Date(CONVERT(Datetime, '0000-00-00 00:00:00', 102))
is BETWEEN '2012-03-14 12:23:00' AND 'Now'
GO
回答by Kaf
SELECT * FROM [Submission]
WHERE CONVERT(DATETIME,[DateOnlyColName])
BETWEEN CONVERT(DATETIME,'01/01/2012 12:15:00') AND GETDATE()
回答by codingbadger
You probably want something like this:
你可能想要这样的东西:
Select *
From [CustomerTracking].[dbo].[Submission]
Where Convert(Datetime, [YOUR_DATE_COLUMN], 102) Between '2012-03-14 12:23:00'
AND Getdate()