SRash
SRash

Reputation: 65

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

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

Upvotes: 0

Views: 227

Answers (2)

Mehedi
Mehedi

Reputation: 66

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

Upvotes: 0

RiggsFolly
RiggsFolly

Reputation: 94662

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.

Upvotes: 1

Related Questions