How to convert text column to datetime in SQL?

How do I convert data in a datetime format as the reason for the conversion is that I was trying to get the total number of hours between a datetime column and the date stamp.


  • Avi
    edited November 2022

    Step 1: Add new Column
    ALTER TABLE table_name ADD (duplicate_column datetime);
    Step 2: Update new Column with existing value
    UPDATE table_name SET duplicate_column = str_to_date(column_name, '%d-%m-%Y %h:%i:%s');

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!