CONVERT - String to Datetime - Sybase ASE to PostgreSQL Migration

In Sybase Adaptive Server Enterprise (ASE) you can use CONVERT function to convert a string expression in the specified format (style) to a datetime data type (DATE, DATETIME etc.). In PostgreSQL you can to use TO_TIMESTAMP function.

Note that Sybase ASE CONVERT and PostgreSQL formats are different.

Sybase ASE:

  -- Convert string to datetime
  SELECT CONVERT(DATETIME, '12/28/2022 11:13:31', 110); 
  # 2022-12-28 11:13:31 AM

PostgreSQL:

  -- Convert string to datetime
  SELECT TO_TIMESTAMP('12/28/2022 11:13:31', 'MM/DD/YYYY HH24:MI:SS'); 
  # 2022-12-28 11:13:31+03

Mapping Sybase ASE Datetime Style to PostgreSQL Format

When you convert CONVERT function to TO_TIMESTAMP you have to map the Sybase ASE style to the appropriate format string in PostgreSQL:

Sybase ASE Style PostgreSQL Format String Output Example
101 US 'MM/DD/YYYY' 12/28/2022
110 US 'MM/DD/YYYY HH24:MI:SS' 12/28/2022 11:13:31

Conversion examples:

Sybase ASE PostgreSQL
CONVERT(DATETIME, '12/28/2022', 101) TO_TIMESTAMP('12/28/2022', 'MM/DD/YYYY')
CONVERT(DATETIME, '12/28/2022 11:13:31', 110) TO_TIMESTAMP('12/28/2022 11:13:31', 'MM/DD/YYYY HH24:MI:SS')

For more information, see Sybase ASE to PostgreSQL Migration.