SQLite 3 reference · String Functions

SQLite SUBSTR() Function

Return part of a string starting at a 1-based position, with an optional length. Negative starts count from the end.

SQLite 3

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

substr(X, start, length)  |  substring(X, start, length)

Parameters

ParameterDescription
X The string (other values are converted to text).
start The first character, counting from 1; negative counts back from the end.
length optional How many characters to take; omit it to take the rest.

Return value

Text (or a BLOB slice), or NULL.

Examples

Take part of a stringTry it yourself
SELECT substr('ReadyCamel', 1, 5) AS first5,
       substr('ReadyCamel', 6) AS rest,
       substr('ReadyCamel', -5, 3) AS from_end;

Output

first5 | rest | from_end
Ready | Camel | Cam
Year and month from an ISO dateTry it yourself
SELECT order_date, substr(order_date, 1, 7) AS month
FROM orders
LIMIT 3;

Output

order_date | month
2026-01-05 | 2026-01
2026-01-12 | 2026-01
2026-02-02 | 2026-02

Common mistakes

  • Positions start at 1, not 0. substr(x, 0, 3) returns only the first two characters.

Version history

VersionChange
SQLite 3.34.0substring() is accepted as another name for substr().

In other languages

Was this page helpful?