Tag Archive Date

Convert date to local timezone

Check code example below :


  DATA : lw_timestamp     TYPE timestamp,
         lw_date_syst     TYPE datum,
         lw_time_syst     TYPE uzeit,
         lw_date_local    TYPE datum,
         lw_time_local    TYPE uzeit,
         lw_syst_timezone TYPE tznzone.

  " Retrieve system timezone
  " ------------------------
  SELECT SINGLE tzonesys
       FROM ttzcu
       INTO lw_syst_timezone.

  " Convert date / time to system timestamp
  " ---------------------------------------
  CONVERT DATE lw_date_syst
          TIME lw_time_syst
          DAYLIGHT SAVING TIME 'X'           " Manage summer/winter time
          INTO TIME STAMP lw_timestamp
          TIME ZONE lw_syst_timezone.

  " Convert timestamp to local date/time
  " ------------------------------------
  CONVERT TIME STAMP lw_timestamp TIME ZONE sy-zonlo
  INTO DATE lw_date_local
       TIME lw_time_local.

Search tag: fuseau horaire, heure, convertir,

Convert date to posting date

Posting date = date comptable.
Use the FM below :


  CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
    EXPORTING
      i_gjahr        = gv_gjhar
      i_periv        = gc_24
      i_poper        = gv_poper
    IMPORTING
      e_date         = s_fkdat-low
    EXCEPTIONS
      input_false    = 1
      t009_notfound  = 2
      t009b_notfound = 3
      OTHERS         = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
    EXPORTING
      i_gjahr        = gv_gjhar
      i_periv        = gc_24
      i_poper        = gv_poper
    IMPORTING
      e_date         = s_fkdat-high
    EXCEPTIONS
      input_false    = 1
      t009_notfound  = 2
      t009b_notfound = 3
      OTHERS         = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

 

Search tag: date comptable, conversion

 

Convert date to external format

Convert date to default external format :


DATA : lw_date_ext TYPE char10,
       lw_date TYPE datum. 
WRITE lw_date TO lw_date_ext.

Other way to do that since 7.40 :


DATA lv_date TYPE d value '20190718'.
DATA(l_user_format) = |{ lv_date DATE = USER }|. "RAW, ISO, USER, ENVIRONMENT
WRITE l_user_format.

Convert date to specified external format :


DATA : lw_date_ext TYPE char10,
       lw_date     TYPE datum.

  CALL FUNCTION 'SLS_MISC_CONVERT_TO_DATE'
    EXPORTING
      p_date        = lw_date
      p_date_format = 'DD.MM.YYYY'
    IMPORTING
      p_date_string = lw_date_ext.

See also Convert date to internal format.

Convert date to internal format

With 7.40 :


DATA : lw_date_ext TYPE char10,
       lw_date TYPE datum.

lw_date = |{ lw_date_ext+6(4) }{ lw_date_ext+3(2) }{ lw_date_ext(2) }|.

With FM :


DATA : lw_date_ext TYPE char10,
       lw_date     TYPE datum.

  CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
    EXPORTING
      date_external = lw_date_ext    " ==> 10.10.2017
    IMPORTING
      date_internal = lw_date        " ==> 20171010
    EXCEPTIONS
      date_external_is_invalid = 1.

See also Convert date to external format.

Add day/month/year to a date in ABAP

Add days to date

You can simply add integer value if your variable is typed DATUM.


  DATA : lw_date  TYPE  sy-datum.
  lw_date = '20170927'.
  lw_processed_date = lw_date + 5.
* ==> lw_processed_date = 20171002

Read More