mysql比较两个时间字段,Mysql比较两个datetime字段

I want to compare two dates with time, I want all the results from tbl where date1 > date2

Select * From temp where mydate > '2009-06-29 04:00:44';

but it is just comparing dates not time. it is giving me all the result set of today's date

'2009-06-29 11:08:57'

'2009-06-29 11:14:35'

'2009-06-29 11:12:38'

'2009-06-29 11:37:48'

'2009-06-29 11:52:17'

'2009-06-29 12:12:50'

'2009-06-29 12:13:38'

'2009-06-29 12:19:24'

'2009-06-29 12:27:25'

'2009-06-29 12:28:49'

'2009-06-29 12:35:54'

'2009-06-29 12:36:54'

'2009-06-29 12:49:57'

'2009-06-29 12:58:04'

'2009-06-29 04:13:20'

'2009-06-29 04:56:19'

'2009-06-29 05:00:23'

'2009-06-29 05:04:26'

'2009-06-29 05:08:17'

'2009-06-29 05:26:57'

'2009-06-29 05:29:06'

'2009-06-29 05:32:11'

'2009-06-29 05:52:07'

Thanks in advance!

解决方案

The query you want to show as an example is:

SELECT * FROM temp WHERE mydate > '2009-06-29 16:00:44';

04:00:00 is 4AM, so all the results you're displaying come after that, which is correct.

If you want to show everything after 4PM, you need to use the correct (24hr) notation in your query.

To make things a bit clearer, try this:

SELECT mydate, DATE_FORMAT(mydate, '%r') FROM temp;

That will show you the date, and its 12hr time.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值