Format the return of the MySQL Now () function

4

So folks.

I need to know if I'm going to just send the hours H: i: s from the NOW() function in the database, or send the NOW() complete and then only search the hours?

    
asked by anonymous 13.07.2015 / 19:28

2 answers

5

You can do the insert only with the function now() remember that to use the time it is necessary that the field be datetime or timestamp , to display the formatted results use the function date date_format () of mysql, use the minute or second to make comparisons.

SELECT DATE_FORMAT(now(), '%H:%i:%s')

//exemplo do sqlfiddle
SELECT id, date_format(data,'%H:%i:%s') FROM datas WHERE hour(data) = 14

Example - sqlfiddle

    
13.07.2015 / 19:33
4

Try formatting the output value, eg: SELECT DATE_FORMAT(NOW(), '%H:%i:%s');

    
13.07.2015 / 19:32