Skip to Content

How many hours has a day ? (DST)

Hi guys,

I'm required to check if the day has 23, 24 or 25 hours, and which is which.

I tried looking for some DTS functions within SAP but none of the return an answer, only set the DTS times and BASIS functions.

If you don't take into account DST the day has 24 hours, 1440 min, 86400 seconds ... no functions give me more or less if I run 27 03 2016 or 30 10 2016.

Used functions like TSTR_CALC_DURATION, TSTR_CALC_TIME, CCU_TIMESTAMP_DIFFERENCE, SD_DATETIME_DIFFERENCE, L_TO_TIME_DIFF

Any suggestions ?

Regards,

Marius

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Nov 17, 2016 at 06:13 PM

    (DST = Daylight Saving Time)

    To get the "number of seconds in a day" (in the special way you are requesting), run the following statement twice with times 00:00:00 and 23:59:59, to get the corresponding UTC timestamps, and subtract one from the other using method SUBTRACT of class CL_ABAP_TSTMP :

    CONVERT DATE ... TIME ... TIMEZONE ... DAYLIGHT SAVING TIME ...
    Add comment
    10|10000 characters needed characters exceeded

    • The following code will return 90000 (25 hours) because CET is configured to switch from DST to non-DST at 30/10/2016 2am.

      REPORT.
      
      DATA: lv_firstday TYPE timestampl, lv_nextday TYPE timestampl, lv_val TYPE timestampl.
      CONVERT DATE '20161030' TIME '000000' INTO TIME STAMP lv_firstday TIME ZONE 'CET'.
      CONVERT DATE '20161031' TIME '000000' INTO TIME STAMP lv_nextday TIME ZONE 'CET'.
      CALL METHOD cl_abap_tstmp=>subtract EXPORTING tstmp1 = lv_nextday tstmp2 = lv_firstday RECEIVING r_secs = lv_val.
      WRITE: /1 lv_val.

      by the way, sorry I misleaded you with DAYLIGHT SAVING TIME which is useless in our case (I guess DST indicator would never change at midnight).

  • Nov 18, 2016 at 09:04 AM

    it can't work if you use UTC

    Add comment
    10|10000 characters needed characters exceeded

    • Probably I understand the things differently ... but doesn't everyone on this planet change the hour (+1h or -1h) at certain times during the year ? I'm not talking about GMT +2 ... that's not Daylight Saving Time.

      Doesn't work with "EET" either (my case of timeozne).