MySQL之间的时间戳Qery不起作用 [英] MySQL Between Timestamp Qery Not Working
问题描述
大家好,
以下是我的MySQL表格,
Hi All,
Below is my MySQL table,
Transations ID TimeStamp
aaa 11 8/1/2013 6:27:15 PM
bbb 11 8/1/2013 6:30:25 PM
ccc 11 8/1/2013 6:32:25 PM
ddd 11 8/1/2013 7:32:18 PM
eee 11 8/1/2013 8:34:32 PM
fff 11 8/1/2013 9:34:32 PM
ggg 11 8/1/2013 9:40:32 PM
hhh 11 8/1/2013 10:00:00 PM
iii 11 8/1/2013 10:11:02 PM
jjj 11 8/1/2013 10:15:04 PM
kkk 11 8/1/2013 10:21:05 PM
bbb 11 8/1/2013 10:27:09 PM
我在MySQL查询下使用以获取两个日期之间的数据,
I am using below MySQL query to fetch data between two dates,
SELECT DISTINCT Transaction_Name FROM `availabilitydb`.`transaction` WHERE Id=11 AND TimeStamp Between '8/1/2013 6:27:25 PM' AND '8/1/2013 9:34:32 PM'
以上查询工作正常,它给我以下数据,
aaa
bbb
ccc
ddd
eee
fff
但是当我改变的时候条件之间的日期值和使用'8/1/2013 6:27:25 PM'和'8/1/2013 10:27:09 PM'在查询中,它不提供任何输出,
The above query works properly and it gives me below data,
aaa
bbb
ccc
ddd
eee
fff
But when I change the date value in the between condition and use '8/1/2013 6:27:25 PM' AND '8/1/2013 10:27:09 PM' in the query, it does not give any output,
SELECT DISTINCT Transaction_Name FROM `availabilitydb`.`transaction` WHERE Id=11 AND TimeStamp Between '8/1/2013 6:27:25 PM' AND '8/1/2013 10:27:09 PM'
输出=>空白
我不知道为什么会这样,查询无法获取数据
'8 / 1/2013 6:晚上27:25'和'8/1/2013 10:27:09 PM'
上表中使用的TimeStamp不是Date,它是Varchar。
我认为这就是为什么它无法获取数据,但它只发生在以下条件下,
'8 / 1 / 2013 6:27:25 PM'AND'8 / 1/2013 10:27:09 PM'
请你检查一下,让我知道什么是可以的完成。
在此先感谢,
Kane
Output=> Blank
I dont know why this is happening, the query is not able to fetch data between
'8/1/2013 6:27:25 PM' AND '8/1/2013 10:27:09 PM'
The TimeStamp used in the above table is not Date, it is Varchar.
I think that's why it is not able to fetch the data, but it is only happening for below condition,
'8/1/2013 6:27:25 PM' AND '8/1/2013 10:27:09 PM'
Could you please check and let me know what can be done.
Thanks in advance,
Kane
推荐答案
所有,请阅读我的评论。要将字符串转换为日期,请使用 STR_TO_DATE [ ^ ]功能。
First of all, please, read my comment. To convert string to date, use STR_TO_DATE[^] function.
这篇关于MySQL之间的时间戳Qery不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!