dqv84329 2015-06-11 09:56
浏览 121
已采纳

当type为timestamp时,查找两个日期之间的记录不起作用

I have one table which having dates and I want to find date between two dates.

For created_date table field, I have used timestamp type. Now I have created following sql query to find records between to dates like 2015-04-15 to 2015-04-21.

My Table

id  created_date
**  *******************
10  2015-04-15 10:49:26
13  2015-04-17 09:49:06
14  2015-04-21 14:59:42
15  2015-05-20 14:26:07
16  2015-06-11 13:25:34

My Select Query

SELECT *
FROM table
WHERE created_date
BETWEEN '2015-04-15'
AND '2015-04-21'
ORDER BY created_date DESC
LIMIT 0 , 10

As I am using timestamp type from above table, sql is not working becouse I am comparing with this data formate YYYY-MM-DD. I want to get records with using timestamp type and dont want to change from table but fetch results without reading HH:MM:SS.

For example, If I search with this two dates: 2015-04-15 to 2015-04-21

I want this records:

id  created_date
**  *******************
10  2015-04-15 10:49:26
13  2015-04-17 09:49:06
14  2015-04-21 14:59:42

Any Idea how to get records like this :)

Thanks.

  • 写回答

4条回答 默认 最新

  • drpiqlzrh62917192 2015-06-11 10:08
    关注

    You can use MySQl DATE().

    SELECT *
    FROM table
    WHERE DATE(created_date)
    BETWEEN '2015-04-15'
    AND '2015-04-21'
    ORDER BY created_date DESC
    LIMIT 0 , 10
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序