Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How many hours has a day ? (DST)

MariusStoica
Active Participant
0 Kudos

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

5 REPLIES 5

Sandra_Rossi
Active Contributor
0 Kudos

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

0 Kudos

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 Kudos

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

Sandra_Rossi
Active Contributor
0 Kudos

it can't work if you use UTC

0 Kudos

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