Jump to content

Convert Time help


topflight

Recommended Posts

In my table I have a column called "dtime" and "atime". However when I received the CSV and uploaded it to the database the times were not in time format they just like a simple string for instance, 1720 is in one of the rows but instead of saying 17:20 it says 1720. I have over 13,000 records. May somebody please give me an example on how I can change all those to the correct time format thanks.

Link to comment
Share on other sites

One way (gives a TIME value with :00 seconds) -

SELECT STR_TO_DATE('1720', '%H%i');

 

Another way (gives a string in the format you are showing) -

SELECT CONCAT(LEFT('1720', 2),':',RIGHT('1720',2));

 

Replace the '1720' term in each of the above with your column name (with no single-quotes.)

 

Are the hours always two digits, with leading zeros?

 

Link to comment
Share on other sites

The following will produce a TIME value from either a xxx starting value or a xxxx starting value -

SELECT TIME(CONCAT('630','00'));

 

As previously stated, you would replace the 'xxx' term with wherever your starting value is at.

Link to comment
Share on other sites

Kind of depends of where the data is now and where you want to get it to. Do you want to do this when you import CSV data or is it already in a column in a table and you want to set an actual column to the converted valued?

Link to comment
Share on other sites

Kind of depends of where the data is now and where you want to get it to. Do you want to do this when you import CSV data or is it already in a column in a table and you want to set an actual column to the converted valued?

 

it already in a column in a table and I want to update an actual column to the converted valued?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.