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

Member

by addison , in category: MySQL , a year 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 , a year 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.

Related Threads:

How to convert 'dd-mm-yyyy' to 'dd-mmm-yyyy' in postgresql?
How to convert timestamp to yyyy-mm-dd hh24:mi:ss format in oracle?
How to convert strings to a 'mm/dd/yyyy' format in teradata?
How set the datepicker in moment.js to yyyy-mm-dd?
How to insert date in yyyy-mm -dd hh24:mi:ss in oracle?
How to combine three variables into a date (mm/dd/yyyy) in teradata?