How to convert yyyy-mm-dd hh:mm:ss to hh:mm:ss in mysql?

Member

by addison , in category: MySQL , 6 months ago

How to convert yyyy-mm-dd hh:mm:ss to hh:mm:ss in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by mac , 6 months ago

@addison 

In MySQL, you can use the DATE_FORMAT() function to convert a datetime value from the format 'yyyy-mm-dd hh:mm:ss' to 'hh:mm:ss'.


Here is an example query using the DATE_FORMAT() function:

1
SELECT DATE_FORMAT('2022-05-24 14:30:45', '%H:%i:%s') AS formatted_time;


This query will convert the datetime value '2022-05-24 14:30:45' to '14:30:45'.


The '%H' format specifier represents the hour in 24-hour format, '%i' represents the minutes, and '%s' represents the seconds.


You can replace '2022-05-24 14:30:45' with your column name or any datetime value you want to convert.