Reputation: 99
I have a string column that is missing leading 0's. An example of this is
9/14/2006 4:5:19 PM
It should have a 0 to make it 09/14/2006 4:05:19 PM
Upvotes: 0
Views: 70
Reputation: 8973
I don't want to do anything with what was already created just create my own new column with leading 0's for those items
You can create your column with proper date datatype, it will be much easier to query and format the date as you wish
Use str_to_date to convert string to date
select str_to_date(my_dt,'%m/%d/%Y %I:%i:%s %p')
from test;
Then update the newly created column :
update test
set correct_dt = str_to_date(my_dt,'%m/%d/%Y %I:%i:%s %p');
You can find all the steps above in the fiddle here: https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=6b53020805776571c7c9f644eb94123c
Upvotes: 1