0

我的表中有以下值

有哪些数据

Select * From TimeSheetLogs where InTimeStamp <= '1/22/2013'

当我执行上述查询时,我得到空值

但如您所见,我有 3 个数据,日期字段为 2013 年 1 月 22 日

那我做错了什么?

谢谢

4

4 回答 4

3

这是正确的,因为

'1/22/2013 19:21' > '1/22/2013 00:00'
于 2013-01-22T20:28:44.450 回答
0

您可能需要先截断日期以删除时间部分。然后将双方转换为日期数据类型。字符串 '1/22/2013' 是字符串,而不是日期。通过查看数据,您的 InTimeStamp 是时间戳数据类型。您无法将日期或时间戳与字符进行比较,而无需将字符转换为日期。我不确定您使用的是什么数据库。这就是您在 Oracle 中使用 to_date 函数进行转换的方式。

SELECT in_date, compare_date
  FROM
 (-- This is your InTimeStamp on the fly
  SELECT trunc(to_timestamp('2013-01-22 16:21:19.273', 'yyyy-mm-dd hh24:mi:ss.ff')) in_date -- this is your InTimeStamp  
      , to_date('1/22/2013', 'mm/dd/yyyy') compare_date
   FROM dual
 )
 WHERE in_date <= compare_date
/

Now you can compare two dates below - this is the output of above query:

in_date     compare_date
----------  ------------
1/22/2013   1/22/2013
于 2013-01-22T21:10:28.730 回答
0
Select * From TimeSheetLogs 
where InTimeStamp <= select convert(datetime,'1/22/2013',101)
于 2013-01-23T07:28:44.183 回答
0

根据我对@Zdravko 的好回答的评论,您只需要输入您的日期:

Select * From TimeSheetLogs where CAST(InTimeStamp as Date) <= '1/22/2013' 
于 2013-01-22T20:36:07.980 回答