Questions  /  Working with Data  /  SQL

How to convert date data into a string or numeric value

Learn how to extract day, month or year values from date columns.

The to_char PostgreSQL function allows CARTO users to convert dates (or numbers) into strings:

UPDATE
  table_name
SET
  date_string = to_char(date_column, 'YYYY-MM-DD')

The extract function also converts from time to number, but is more specific because it lets you select the part of the timestamp you are interested in:

UPDATE
  table_name
SET 
  hour = extract(hour from date_column)