Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Date and Time Processing →  Date Fields and Time Fields →  Access to Date Fields and Time Fields 

Character-Like Access to Date Fields and Time Fields

Character-like access to character-like content of date fields and time fields is evaluated in a character-like manner. The character-like nature of date fields and time fields can be exploited, for example, to access detailed information. To avoid unexpected results from this type of access, the validity of the content of the date or time fields must be verified. Most statements and functions used in string processing are not suitable for editing date fields and time fields because they generally produce invalid content.

Other versions: 7.31 | 7.40 | 7.54


Example

The following example demonstrates how substring functions can be used to extract the components year, month, day, hour, minute, and second from date fields and time fields.

DATA: date TYPE d,
      time TYPE t.

DATA: year   TYPE i,
      month  TYPE i,
      day    TYPE i,
      hour   TYPE i,
      minute TYPE i,
      second TYPE i.

date = sy-datlo.
time = sy-timlo.

year   = substring( val = date off = 0 len = 4 ).
month  = substring( val = date off = 4 len = 2 ).
day    = substring( val = date off = 6 len = 2 ).
hour   = substring( val = time off = 0 len = 2 ).
minute = substring( val = time off = 2 len = 2 ).
second = substring( val = time off = 4 len = 2 ).