Home > OS >  How to convert YYYY-MM-DD HH:MM:SS TO HH:MM:SS IN mysql?
How to convert YYYY-MM-DD HH:MM:SS TO HH:MM:SS IN mysql?

Time:10-14

i have one column (vedu_time) in "YYYY-MM-DD HH:MM:SS" format, i required new column (ganta_time)(new) having only HH:MM:SS for all my records at a time.

Please suggest the query.

vedu_time           | ganta_time  --> New column
--------------------|------------
2021-12-01 07:12:30 | 07:12:30
2021-12-01 07:20:44 | 07:20:44
2021-12-01 13:11:26 | 13:11:26

CodePudding user response:

there is a function called time()

UPDATE table SET ganta_time = TIME(vedu_time);

will take the time and set it into the gana_time column for all your rows in that table.

CodePudding user response:

You can use date_format and put that value in your insert or update query.

$date=date_create("2022-10-14 15:03:23"); // For example purpose 
echo date_format($date,"H:i:s");

Output: 15:03:23

  • Related