-1

I want to select rows greater than current date and time.

I tried this query - SELECT * FROM post WHERE post.pt_date > CURDATE()

I also tried this - SELECT * FROM post WHERE post.pt_date > NOW()

but I get rows greater than current time too.

If current datetime is 20/06/2017 02:55:22 then I want rows greater than same date and in time greater than that hour and minutes.

How can I get dates which are greater than current date? I want to show upcoming dates.

This is the data I have

2017-06-17 18:53:00
2017-06-17 19:01:00
2017-05-30 06:30:04
2017-06-17 06:30:04
2017-06-19 14:14:00
2017-06-19 14:26:00
2017-06-19 15:25:00
2017-06-19 15:31:00
2017-06-19 15:33:00
2017-06-20 15:35:00
2017-06-20 15:58:00
2017-06-19 06:30:04
2017-06-20 16:16:00
2017-06-19 06:30:04
2017-06-19 17:29:00
2017-06-20 17:30:00
2017-06-20 17:47:00
2017-06-20 19:29:00
2017-06-20 19:37:00
2017-06-20 13:59:00
2017-06-20 13:59:00
2017-06-20 14:28:00
2017-06-20 14:33:00
2017-06-20 14:37:00
2017-06-20 14:52:00

Please help thank you..

Sid
  • 2,792
  • 9
  • 55
  • 111

1 Answers1

0

You want to add a day to current date to get future dates. Something like this:

SELECT * FROM post WHERE post.pt_date > DATE_ADD(CURDATE(), INTERVAL 1 DAY);

To ensure that the time is after current time add the second WHERE condition:

    SELECT * FROM post 
    WHERE post.pt_date > DATE_ADD(CURDATE(), INTERVAL 1 DAY)
      AND TIME(post.pt_date) > CURTIME();
under
  • 2,519
  • 1
  • 21
  • 40
  • You were just a second faster, nice answer :) – Florian Humblot Jun 20 '17 at 09:27
  • I dont want future dates like this, I want rows greater than same date and in time greater than that hour and minutes. – Sid Jun 20 '17 at 09:29
  • I dont want interval, I can get todays date but I do not want passed time. @under – Sid Jun 20 '17 at 10:49
  • This is not an interval. This is future dates with time (hour and minutes) after the current time. So if now is 5PM on June 20th, this will return 6PM on June 21st and 22nd, but not 3PM on June 21th. – under Jun 20 '17 at 10:58