如果我有这种情况,我应该在 MS SQL Server 中使用什么正确的日期格式?
--This values here will be supplied by a datetimepicker Control
@StartDate = '05/15/2013 10:00 PM'
@EndDate = '05/16/2013 06:00 AM'
SELECT *
FROM tblSomething
WHERE TransDate >= @StartDate AND TransDate <= @EndDate
如何格式化 TransDate 字段?
这个对吗?
Declare @StartDate as datetime
Declare @EndDate as datetime
set @StartDate = '05/15/2013 10:00 PM'
set @EndDate = '05/16/2013 06:00 AM'
Select * from tblSomething Where convert(varchar(20),TransDate,100) >= convert(varchar(20),@StartDate,100) and convert(varchar(20),TransDate,100) <= convert(varchar(20),@EndDate,100)
上午/下午对我来说很重要的原因是因为我们的员工的交易从晚上 10 点开始,到第二天早上 6 点结束。我需要在该时间范围内提取该员工的交易。