Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Date and Time Processing →  Time Stamp 

CONVERT INTO TIME STAMP

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


CONVERT DATE dat 
        [TIME tim [DAYLIGHT SAVING TIME dst]]
        INTO TIME STAMP time_stamp TIME ZONE tz.

Effect

This statements converts a date specified in dat, a time specified in tim, and a summer time marker specified in dst from the time zone specified in tz into a time stamp and maps the result to the variable time_stamp.

dat, tim, dst, and tz are functional operand positions.

  • dat expects a data object of the type d containing a valid date. Operands of other types are converted to d. If dat contains an invalid value, time_stamp is not changed and sy-subrc is set to 12.
  • tim expects a data object of the type d containing a valid time. Operands of other types are converted to t. If the TIME addition is not specified, the system implicitly uses the initial time "000000" for tim. In tim, only the values 00 to 23 for the hours, and 00 to 59 for the minutes are valid. If tim contains an invalid value, time_stamp is not changed and sy-subrc is set to 12.
  • dst can be specified as a data object of the type c with length 1 containing the value "X" or " ". This controls the behavior of the statement with respect to summer time.
  • If dst has the value "X", the value of tim is adopted as the time specification in summer time.
  • If dst has the value " ", the value of tim is adopted as the time specification in winter time.
If the time zone specified in tz does not have a summer time rule (for example when "UTC" is specified), then the addition DAYLIGHT SAVING TIME does not have any effect. If the addition DAYLIGHT SAVING TIME is not specified, then the value of dst is set to "X" implicitly if the data in tim and dat is in summer time and is set to " " for data in winter time. In the extra hour that is caused by switching from summer time to winter time, tim and dat are interpreted as a time in summer time and dst is set to the value "X". If the value in dst does not match the data in tim and dat (that is, if the value "X" is specified in winter time and the value " " in summer time, time_stamp is not changed and sy-subrc is set to 12.
  • tz expects a data object of the type TZNZONE containing a time zone from the database table TTZZ.
  • If tz is initial, then the time zone is set implicitly to "UTC", time_stamp is given the appropriate data, and sy-subrc is set to 4.
  • If the specified time zone is not found in the database table TTZZ, time_stamp remains unchanged and sy-subrc is set to 8.
  • If the rule set for the specified time zone is incomplete, an exception that cannot be handled is raised.

time_stamp expects a data object of the data type TIMESTAMP or TIMESTAMPL from ABAP Dictionary, in accordance with ABAP type p with length 8 or p with length 11, with seven decimal places. If time_stamp has the data type TIMESTAMPL for the long form, the seconds fractions in the decimal places are initialized when the assignment is made.

When dates are converted to reflect the conversion from the Julian calendar to the Gregorian calendar and the non-existence of the days between 19/5/1582 and 10/14/1582, this returns the same results as the conversion for the days from 10/15/1582 to 10/24/1582 (which do exist).

System Fields

sy-subrc Meaning
0 Local time of specified time zone was converted to time stamp and assigned to the target field
4 Time specification was converted to time stamp without time shift and assigned to the target field.
8 Time specification could not be converted, because the specified time zone is not in the database table TTZZ
12 Time specification could not be converted, because dat, tim, or dst contain invalid or inconsistent values.


Notes

  • Current user-specific, local time specifications and the corresponding local time zones are stored in the system fields sy-datlo, sy-timlo, and sy-zonlo.
  • Specifying daylight saving and winter time after DAYLIGHT SAVING TIME enables you to create different UTC time stamps from matching local time stamps within the extra hour when switching from daylight saving to winter time.
  • When the switch is made from winter to daylight saving time, an hour is lost. For example, in the "CET" time zone in the year 2009, on March 29, the hour between 02:00 and 03:00 does not exist. If you attempt to convert a time during this missing hour, the statement is always terminated with the value 12 for sy-subrc because this time or this local time stamp does not exist.

Example

For the time zone "BRAZIL", the settings apply that are described in the example for CONVERT TIME STAMP in the rule set for time stamps. By specifying the daylight saving and winter time, two different UTC time stamps "20030309033000" and "20030309043000" are created from one local time specification. Without the addition DAYLIGHT SAVING TIME, the UTC time stamp "20030309033000" is created.

DATA: time_stamp     TYPE timestamp, 
      dat TYPE d, 
      tim TYPE t, 
      tz  TYPE ttzz-tzone. 

tz = 'BRAZIL'. 
dat = '20030309'. 
tim = '013000'. 

CONVERT DATE dat TIME tim DAYLIGHT SAVING TIME 'X' 
        INTO TIME STAMP time_stamp TIME ZONE tz. 
WRITE: / time_stamp. 

CONVERT DATE dat TIME tim DAYLIGHT SAVING TIME ' ' 
        INTO TIME STAMP time_stamp TIME ZONE tz. 
WRITE: / time_stamp. 

Exceptions


Non-Catchable Exceptions

  • Cause: Inconsistent control tables for the conversion.
    Runtime Error: CONVERT_TSTMP_INCONSISTENT_TAB