Home Forums MYSQL How to convert text column to datetime in SQL?

Viewing 1 reply thread
  • Author
    Posts
    • #114
      vanshika
      Participant

      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.

    • #115
      avi
      Participant

      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');

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
Scroll to Top