Her er et test setup du kan lege med.
Tabel setup:
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for test
-- ----------------------------
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`id` int(11) NOT NULL auto_increment,
`dt` datetime default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
-- ----------------------------
-- Records
-- ----------------------------
INSERT INTO `test` VALUES ('1', '2008-07-19 01:42:33');
INSERT INTO `test` VALUES ('2', '2008-07-10 01:42:41');
Og her er SQL til datetime:
SELECT
id,
EXTRACT(DAY FROM dt) as d,
EXTRACT(MONTH FROM dt) as m,
EXTRACT(YEAR FROM dt) as y,
dt
FROM test
ORDER BY d ASC, m ASC, y ASC
God fornøjelse
Indlæg senest redigeret d. 19.07.2008 01:47 af Bruger #10216