Robin
Robin

Reputation: 591

MySQL Where DateTime is greater than today

I want to get every record from my MySQL database which is greater than today.

Sample:

"Go to Lunch","2014-05-08 12-00-00"
"Go to Bed","2014-05-08 23-00-00"

Output should only:

"Go to Bed","2014-05-08 23-00-00"

I use the DateTime for the Date Column

Already searched:

But this does not work for me.

QUERY(FOR PHP):

SELECT `name`,`date` FROM `tasks` WHERE `tasks`.`datum` >= DATE(NOW())

OR (FOR PhpMyAdmin)

SELECT `name`,`date` FROM `tasks` WHERE `tasks`.`datum` >= 2014-05-18 15-00-00;

How can I write the working query?

Upvotes: 25

Views: 154604

Answers (3)

Kodebetter
Kodebetter

Reputation: 47

SELECT * 
FROM customer 
WHERE joiningdate >= NOW();

Upvotes: -3

echo_Me
echo_Me

Reputation: 37233

I guess you looking for CURDATE() or NOW() .

  SELECT name, datum 
  FROM tasks 
  WHERE datum >= CURDATE()

LooK the rsult of NOW and CURDATE

   NOW()                    CURDATE()        
   2008-11-11 12:45:34      2008-11-11       

Upvotes: 9

juergen d
juergen d

Reputation: 204766

Remove the date() part

SELECT name, datum 
FROM tasks 
WHERE datum >= NOW()

and if you use a specific date, don't forget the quotes around it and use the proper format with :

SELECT name, datum 
FROM tasks 
WHERE datum >= '2014-05-18 15:00:00'

Upvotes: 55

Related Questions