Use LENGTH
:
SUBSTR(your_string, 1,LENGTH(your_string)-4)
However, in your case is just specify fixed positions:
SUBSTR(tablename.time, 12, 8)
Question
Using SQLite.
ltrim(ltrim(substr(tablename.time, 11),'0123456789'),'-') as main_time
I have the above trim
function which removes the first 11 characters from my string below.
2013-10-28 09:29:57.987 -- Original String.
09:29:57.987 -- New String.
However I'd still like to remove the last four characters from the end of the string, turning it into the below:
09:29:57
Solution
Use LENGTH
:
SUBSTR(your_string, 1,LENGTH(your_string)-4)
However, in your case is just specify fixed positions:
SUBSTR(tablename.time, 12, 8)
OTHER TIPS
To extract the time from such a string, just use the time function:
time(tablename.time)