does anyone of you have suggestions how to convert a given UTC timestamp into the date and time of the system time zone?
Converting from an UTC timestamp to the users local time zone is easy, you could just do:
CONVERT TIME STAMP lv_utc_timestamp TIME ZONE sy-zonlo
INTO DATE lv_local_date TIME lv_local_time.
But how to do it for the system time - system time is needed in many situations e.g. when calling the JOB_CLOSE function module. The only solution I have come up so far is like that:
SELECT SINGLE * FROM TTZCU INTO ls_ttzcu.
CONVERT TIME STAMP lv_utc_timestamp TIME ZONE ls_ttzcu-tzonesys
INTO DATE lv_system_date TIME lv_system_time.
Is this already the best solution or can the system time zone be retrieved in another way? Is there always a valid time zone to be expected from the entry in table TTZCU? Any ideas?
UPDATE: @rmtiwari suggested on twitter, that the FLAGACTIVE flag of TTZCU should also be checked, so the modified statement would be
SELECT SINGLE * FROM TTZCU INTO ls_ttzcu WHERE flagactive = abap_true.
CONVERT TIME STAMP lv_utc_timestamp TIME ZONE ls_ttzcu-tzonesys
INTO DATE lv_system_date TIME lv_system_time.
UPDATE2: I have found another way, which is probably the best:
cl_abap_tstmp=>systemtstmp_utc2syst(
EXPORTING utc_tstmp = lv_utc_timestamp
IMPORTING syst_date = lv_system_date " System Date
syst_time = lv_system_time " System Time
).
Say you have time stamp for local time, split that to date and time DATA: tstamp TYPE timestamp value '20070525183545', d TYPE D, t TYPE T, tstamp_UTC type timestamp. d = tstamp+0(8). t = tstamp+8(8). CONVERT DATE d TIME t INTO TIME STAMP tstamp_UTC TIME ZONE 'UTC'.
The best way seems to be:
cl_abap_tstmp=>systemtstmp_utc2syst(
EXPORTING utc_tstmp = lv_utc_timestamp
IMPORTING syst_date = lv_system_date " System Date
syst_time = lv_system_time " System Time
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With