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: 

Error while creating timestamp in local (CET) timezone

SuhaSaha
Advisor
Advisor
0 Kudos

Hello fellow SDNers,

I am getting the DST timestamp (-1 hrs) when i try to create the timestamp.

This is the code that i have written -

  1. CONVERT DATE sy-datlo
  2.         TIME sy-timlo
  3.         INTO TIME STAMP DATA(locl_tstmp)
  4.         TIME ZONE sy-zonlo.

Debugging session looks like this -

SAP documentation on CONVERT INTO TIMESTAMP says & i quote -


If the addition DAYLIGHT SAVING TIME is not specified, then the value of dst is set to "X" implicitly if the data in tim and dat is in summer time and is set to " " for data in winter time.

Refer. - ABAP Keyword Documentation

Am i missing something?

BR,

Suhas

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Suhas

The output is correct.

The statement converts your date,time,timezone combination to system timestamp (UTC always).

I think you just want to get output as 20140217110409, the literal combination of datlo and timlo.

In this case you can "lie" to the statement, saying that timezone is UTC. As a result, UTC to UTC conversion would give you unchanged datetime.

  1. DATA locl_tstmp TYPE timestamp.
  2. DATA utc TYPE sy-zonlo VALUE 'UTC'.
  3. DATA a TYPE sy-datlo VALUE '20140217'.
  4. DATA b TYPE sy-timlo VALUE '110409'.
  5. DATA c TYPE sy-zonlo VALUE 'CET'.
  6. CONVERT DATE a
  7.         TIME b
  8.         INTO TIME STAMP locl_tstmp
  9.         TIME ZONE c.
  10. WRITE😕 'suhas', locl_tstmp.
  11. CONVERT DATE a
  12.         TIME b
  13.         INTO TIME STAMP locl_tstmp
  14.         TIME ZONE utc.
  15. WRITE😕 'utc winter', locl_tstmp.
  16. a = '20141017'.
  17. CONVERT DATE a
  18.         TIME b
  19.         INTO TIME STAMP locl_tstmp
  20.         TIME ZONE utc.
  21. WRITE😕 'utc summer', locl_tstmp.

Let me know if i understood the requirement incorrectly.

8 REPLIES 8

nabheetscn
Active Contributor
0 Kudos

Hi Suhas

I tried one more thing apart from this. I create a local variable and give it a summer date. Now the timestamp contains 2 hours less.

So for winter for me it is subtracting one hour and for summer two hours without daylight addition.

Nabheet

0 Kudos

So for winter for me it is subtracting one hour and for summer two hours without daylight addition.

I think you meant the other way round, DST is active in summer & not in winters

Former Member
0 Kudos

Check the timezone settings in tcode STZBC

0 Kudos

DEBOPRIYO MALLICK wrote:

Check the timezone settings in tcode STZBC

I had already done that before posting, sorry for not mentioning that in my post.

Imo no sane person would mess with these anyway.

BR,

Suhas

0 Kudos

Yes you are right what if we use sy-uzeit in place of local time?

0 Kudos

Doesn't help either

I never thought about the difference between System & User Timezones, but yes in my case both are same.

Since in my case the user TZ = system TZ.

BR,

Suhas

Former Member
0 Kudos

Hi Suhas

The output is correct.

The statement converts your date,time,timezone combination to system timestamp (UTC always).

I think you just want to get output as 20140217110409, the literal combination of datlo and timlo.

In this case you can "lie" to the statement, saying that timezone is UTC. As a result, UTC to UTC conversion would give you unchanged datetime.

  1. DATA locl_tstmp TYPE timestamp.
  2. DATA utc TYPE sy-zonlo VALUE 'UTC'.
  3. DATA a TYPE sy-datlo VALUE '20140217'.
  4. DATA b TYPE sy-timlo VALUE '110409'.
  5. DATA c TYPE sy-zonlo VALUE 'CET'.
  6. CONVERT DATE a
  7.         TIME b
  8.         INTO TIME STAMP locl_tstmp
  9.         TIME ZONE c.
  10. WRITE😕 'suhas', locl_tstmp.
  11. CONVERT DATE a
  12.         TIME b
  13.         INTO TIME STAMP locl_tstmp
  14.         TIME ZONE utc.
  15. WRITE😕 'utc winter', locl_tstmp.
  16. a = '20141017'.
  17. CONVERT DATE a
  18.         TIME b
  19.         INTO TIME STAMP locl_tstmp
  20.         TIME ZONE utc.
  21. WRITE😕 'utc summer', locl_tstmp.

Let me know if i understood the requirement incorrectly.

0 Kudos

The statement converts your date,time,timezone combination to system timestamp (UTC always).

My bad - should have read the SAP documentation thoroughly (ABAP Keyword Documentation).


Time stamps in the ABAP runtime environment are POSIX time stamps independent of time zone.


In this case you can "lie" to the statement, saying that timezone is UTC.

I don't need a workaround. I just wanted to know why did the statement always return UTC timestamp irrespective of the TZ (and the DST settings)

I don't need the CONVERT INTO TIMESTAMP as well, i'll use GET TIMESTAMP. The reason i got confused was that the documentation of GET TIMESTAMP clearly states that it will generate UTC timestamp, but that of CONVERT INTO TIMESTAMP doesn't

So i assumed that the timestamps will be created in the TZ of the AppServer .

Thanks anyway.

BR,

Suhas

Note to me - When in doubt RTFM, always!