Skip to Content
0

How many hours has a day ? (DST)

Nov 17, 2016 at 08:57 AM

77

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Sandra Rossi Nov 17, 2016 at 06:13 PM
0

(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 ...
Show 2 Share
10 |10000 characters needed characters left characters exceeded

I tried it ... same result :( 86400 secs, or .. if I use 235959, 86399 secs :(

REPORT zpp_test.



DATA: lv_ts1 TYPE timestampl,

      lv_ts2 TYPE timestampl,

      lv_val TYPE timestampl.



CONVERT DATE '20160327' TIME '000000' DAYLIGHT SAVING TIME 'X' INTO TIME STAMP lv_ts1 TIME ZONE 'UTC'.

CONVERT DATE '20160328' TIME '000000' DAYLIGHT SAVING TIME 'X' INTO TIME STAMP lv_ts2 TIME ZONE 'UTC'.



CALL METHOD cl_abap_tstmp=>subtract

  EXPORTING

    tstmp1 = lv_ts1

    tstmp2 = lv_ts2

  RECEIVING

    r_secs = lv_val.



WRITE: /1 lv_val.
0

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).

0
Sandra Rossi Nov 18, 2016 at 09:04 AM
0

it can't work if you use UTC

Show 1 Share
10 |10000 characters needed characters left 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).

0