DATEPART Function - Sybase ASE to Oracle Migration

In SAP Sybase Adaptive Server Enterprise (ASE) you can use the DATEPART function to extract the specified unit (a date part such as year, month, day etc.) from a datetime value as integer.

In Oracle you can use an expression with TO_NUMBER and TO_CHAR functions with the specific format type. Note that DATEPART units differ from TO_CHAR format models.

Sybase ASE:

  -- Get the day part
  SELECT DATEPART(dd, '2026-07-14');
  /* 14 */

Oracle:

  -- Get the day part
  SELECT TO_NUMBER(TO_CHAR(DATE '2026-07-14', 'dd')) FROM dual;
  /* 14 */

Mapping Sybase ASE DATEPART Units to Oracle TO_CHAR Format

You can map Sybase ASE DATEPART units to the appropriate TO_CHAR format models in Oracle as follows:

Sybase ASE Oracle Output Example
yy year DATEPART(yy, GETDATE()) TO_NUMBER(TO_CHAR(SYSTIMESTAMP, 'YYYY')) 2026
qq quarter DATEPART(qq, GETDATE()) TO_NUMBER(TO_CHAR(SYSTIMESTAMP, 'Q')) 3
mm month DATEPART(mm, GETDATE()) TO_NUMBER(TO_CHAR(SYSTIMESTAMP, 'MM')) 7
wk week DATEPART(wk, GETDATE()) TO_NUMBER(TO_CHAR(SYSTIMESTAMP, 'WW')) 29
dd day DATEPART(dd, GETDATE()) TO_NUMBER(TO_CHAR(SYSTIMESTAMP, 'DD')) 14
dy dayofyear DATEPART(dy, GETDATE()) TO_NUMBER(TO_CHAR(SYSTIMESTAMP, 'DDD')) 195
dw weekday DATEPART(dw, GETDATE()) TO_NUMBER(TO_CHAR(SYSTIMESTAMP, 'D')) 3
hh hour DATEPART(hh, GETDATE()) TO_NUMBER(TO_CHAR(SYSTIMESTAMP, 'HH24')) 17
mi minute DATEPART(mi, GETDATE()) TO_NUMBER(TO_CHAR(SYSTIMESTAMP, 'MI')) 31
ss second DATEPART(ss, GETDATE()) TO_NUMBER(TO_CHAR(SYSTIMESTAMP, 'SS')) 11
ms millisecond DATEPART(ms, GETDATE()) TO_NUMBER(TO_CHAR(SYSTIMESTAMP, 'FF3')) 777
us microsecond DATEPART(us, GETDATE()) TO_NUMBER(TO_CHAR(SYSTIMESTAMP, 'FF6')) 317

For more information, see Sybase ASE to Oracle Migration.