Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Datetime displays 0:00:00

Tags:

sql

mysql

When I run a query to display a datetime in MySQL, the time displayed is sometimes 0:00:00, even though when I query for the hour, minute, or second, I get the values I would expect.

datetime query and response

As you can see, the stored time is 9:24:23, but the displayed time is 0:00:00.

The column datetime has a data type datetime. Is there a way to get my queries to display the correct time without doing a terrible concat(hour,minute,second) workaround?

EDIT: Sometimes, I get the datetime as expected, and I don't see any difference between the times that display and those that don't.

enter image description here

Here's the table setup:

enter image description here

like image 503
Ealau Avatar asked Sep 14 '25 23:09

Ealau


1 Answers

This would appear to be a problem in user interface. One solution is to format the value as a string:

select date_format(datetime, '%Y-%m-%d %H:%i:%s')

This should print correctly.

like image 187
Gordon Linoff Avatar answered Sep 17 '25 15:09

Gordon Linoff