Hey! This content applies only to previous CARTO products

Please check if it's relevant to your use case. On October 2021 we released a new version of our platform.
You can learn more and read the latest documentation at docs.carto.com

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)