Suggest appropriate mysql date function

I have a date field of type datatype datetime , although H:s:i preserved, but I do not want to take into account when checking that I use CURDATE() , in which the query condition is, but 'H: S: I' considers, for example ,

 SELECT ('2013-01-10 05:10:50' <= CURDATE()) FROM dual 

Above the query returns false (0), why not true (1), because 2013-01-10 05:10:50 is the elapsed time. In short, I want to keep "H: s: i", but should not be taken into account when checking what the MySql function is suitable for?

Updated below

I do not want to use NOW() and SYSDATE() because these functions will consider H:s:i when checking, so I used CURDATE() , but the expected result is different when I use CURDATE() .

+4
source share
5 answers

You can try the following:

 SELECT DATE('2013-01-10 05:10:50') <= CURDATE() FROM DUAL; SELECT '2013-01-10 05:10:50' <= DATE_FORMAT(NOW(), '%Y-%m-%d 23:59:59') FROM DUAL; 
+1
source

The query returns false because CURDATE() returns a date not a date and time. A simple date return means 2012-01-10 00:00:00 when compared with the date and time. Thus, CURDATE() not earlier than 2013-01-10 05:10:50 .

I suggest you use NOW() - which returns the date and time.

Docs for NOW() here

+2
source

CURDATE() does not include time, so it should be 00:00:00 or midnight at the 9th / 10th border. If you want to do this check, use NOW() instead

+2
source

Use now() instead of curdate() .

now() returns the current date and time, while curdate() returns the current date, which is passed to the time for comparison and the goven time component, if 00:00:00

0
source

you need to use now () or current_timestamp

0
source

All Articles