MySQL:按时间排序不正确,中午 12 点和凌晨 1 点

MySQL: Order By time is not correct with 12 AM and 1 AM

我面临的问题是MySQL正在考虑

2015-02-12 01:08:40

小于

2015-02-12 12:54:49

我的查询

SELECT DISTINCT(time) FROM `dcn_payments` ORDER BY `time` ASC

我的Table结构

CREATE TABLE `x` (
  `payId` int(8) unsigned NOT NULL AUTO_INCREMENT,
  `receipt` char(0) DEFAULT NULL,
  `amount` decimal(13,2) NOT NULL,
  `pack` char(20) NOT NULL,
  `date` date NOT NULL,
  `time` char(19) NOT NULL,
  `status` tinyint(1) unsigned NOT NULL,
  `opId` int(4) NOT NULL,
  `cId` int(7) NOT NULL,
  `lnId` smallint(4) NOT NULL,
  PRIMARY KEY (`payId`),
  KEY `cId` (`cId`),
  KEY `opId` (`opId`),
  CONSTRAINT `cId` FOREIGN KEY (`cId`) REFERENCES `customers` (`cId`) ON UPDATE CASCADE,
  CONSTRAINT `x1` FOREIGN KEY (`opId`) REFERENCES `operators` (`opId`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1001 DEFAULT CHARSET=latin1

我的输出

time Ascending 1
2015-02-12 01:02:05
2015-02-12 01:08:27
2015-02-12 01:08:40
2015-02-12 12:54:49
2015-02-12 12:55:43
2015-02-12 12:56:33
2015-02-12 12:57:02

编辑 我正在将日期 ('Y-m-d h:i:s') 插入到我的数据库列中,我做错了吗? 因为我刚刚在本地主机上插入 12:54 (hh:mm) 而不是 (00:54),我的系统时间是 12 小时(如果重要的话)

12:54:49 大约是五分钟差一点,PM01:08:40 大约 上午 一点十分。上午 1 点将表示为 13:00:00,因此 MySQL 在这里正确排序。

您想插入 date('Y-m-d H:i:s') 而不是 date('Y-m-d h:i:s')。大写的 H 是 24 小时制,小写的 h 是 12 小时制。 MySQL 使用 24 小时格式。