-1

就是这样,我需要找出那个“”那天不应该在那里的sql。而且我最终也会发现我是否将它设置为21:00,所以1.21必须消失!

现在它适用于日期,但现在似乎是时候了。

这不起作用

SELECT title, Dato, Tidspunkt, antal 
FROM tilmeldt 
WHERE Dato >= CURDATE() Tidspunkt > TIME() 
ORDER BY Dato DESC

这工作 100%

SELECT title, Dato, Tidspunkt, antal 
FROM tilmeldt 
WHERE Dato >= CURDATE() 
ORDER BY Dato DESC

问题是:当它到了必须马上离开的时间时,什么也没有发生。

    CREATE TABLE IF NOT EXISTS `tilmeldt` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(150) COLLATE utf8_danish_ci NOT NULL,
  `info` longtext COLLATE utf8_danish_ci NOT NULL,
  `Dato` date NOT NULL,
  `Tidspunkt` time NOT NULL,
  `antal` int(3) NOT NULL,
  `opret_navn` varchar(200) COLLATE utf8_danish_ci NOT NULL,
  `opret_email` varchar(250) COLLATE utf8_danish_ci NOT NULL,
  `opret_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci AUTO_INCREMENT=3 ;

--
-- Data dump for tabellen `tilmeldt`
--

INSERT INTO `tilmeldt` (`id`, `title`, `info`, `Dato`, `Tidspunkt`, `antal`, `opret_navn`, `opret_email`, `opret_id`) VALUES
(1, 'Hello World', '<p>ehhehehe</p>', '2013-08-02', '16:00:00', 0, 'Jesper', 'jp@hey.dk', 1),
(2, 'herherh', '<p>hererh</p>', '2013-08-02', '21:00:00', 1, 'Jesper', 'jp@hey.dk', 1);
4

1 回答 1

2

那是因为您在 where 子句中的条件之间AND或之间缺少逻辑运算符。OR尝试以下操作(我在AND这里假设):

SELECT title, Dato, Tidspunkt, antal 
FROM tilmeldt 
WHERE Dato >= CURDATE() AND Tidspunkt > TIME(NOW()) ORDER BY Dato DESC

更新:

你也缺少函数的参数time()。见这里:https ://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_time 。

或者,您可以使用current_time()如下功能:

SELECT title, Dato, Tidspunkt, antal 
FROM tilmeldt 
WHERE Dato >= CURDATE() AND Tidspunkt > CURRENT_TIME() ORDER BY Dato DESC

选择小提琴中使用的代码(结果中的格式化时间):

SELECT title, Dato, time_format('%H-%i-%s', Tidspunkt) as Tidspunkt, antal 
FROM tilmeldt 
WHERE Dato >= CURDATE() AND Tidspunkt > CURRENT_TIME() ORDER BY Dato DESC
于 2013-08-02T18:29:59.960 回答