Text and date functions

Join text, change case, cut out part of a value, and subtract dates to get days.

Syntax

a || b
UPPER(text) LOWER(text)
SUBSTRING(text, start, length)
date1 - date2
  • Subtracting two dates gives a whole number of days.
  • DATE 'yyyy-mm-dd' writes a date literal.

Example

SELECT UPPER(city), first_name || ' ' || last_name AS full_name, DATE '2025-09-30' - joined_on AS days FROM customers;

Each customer's city in capitals, full name, and days from joining to 30 September 2025.

Tables used: customers. Try it in a lesson below.

Common mistakes

  • || returns NULL if any part is NULL. Use COALESCE to replace a NULL first.

Practise it