Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite trim end characters from string

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
like image 313
T.Rodgerson Avatar asked Dec 20 '22 22:12

T.Rodgerson


1 Answers

Use LENGTH:

SUBSTR(your_string, 1,LENGTH(your_string)-4)

However, in your case is just specify fixed positions:

SUBSTR(tablename.time, 12, 8)
like image 171
LS_ᴅᴇᴠ Avatar answered Jan 04 '23 18:01

LS_ᴅᴇᴠ