Format Mysql Now() function return

Asked

Viewed 509 times

4

So personal.

I need to know if there’s any way to send only the H:i:s hours of the function NOW() in the database, or send the NOW() complete and then fetch only the time?

  • You want to get or save the time?

  • Both. I need the time exact user device entering brazil or japan and save to database.

  • What type of field? date? timestamp?

  • date, but what you think best to work can say @rray , but it has to be the exact time.. from where the person is accessing.. has a way of?

2 answers

5


You can do Insert only with the function now() reminds that to use the time it is necessary to field datetime or timestamp, to display the formatted results use the date function date_format() mysql, use the functions hour, minute or cond 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

4

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.