2023 Jan 05 2:48 PM
Hi all,
We have a Z table where we write UTC timestamps (e.g.20230105130756.0372170).
How can we get the local timezone value of this time stamp (e.g.20230105090756.0372170 for UTC-4)?
TIA,
Luis
2023 Jan 05 5:57 PM
Considering that you want to subtract 4 hours to the UTC timestamp, a workaround would be to subtract 14400 seconds with cl_abap_tstmp=>subtractsecs:
DATA(tstmp) = CONV TZNTSTMPL( '20230105130756.0372170' ).
data(hours) = 4.
data(secs) = hours * 3600.
tstmp = cl_abap_tstmp=>subtractsecs( EXPORTING tstmp = tstmp secs = secs ).
ASSERT tstmp = '20230105090756.0372170'.
As you say you want it to display the time to the user via SE16, a better solution would be to adapt the conversion exit TSTLC (display UTC time in user's time zone), so that it also displays the microseconds.
2023 Jan 05 4:55 PM
Use
CONVERT TIME STAMP time_stamp TIME ZONE tz
INTO [DATE dat]
[TIME tim]
Followed by
CONVERT DATE dat
[TIME tim ]
INTO TIME STAMP time_stamp TIME ZONE tz.
However. In practice it's best to have ALL timestamps in UTC and only change them into the local time zone when display is needed.
2023 Jan 05 5:37 PM
Matthew:
Thanks for your post. The problem with that approach is that we would lose the "decimal" part of the timestamp. Many of our records have the same date and time, and we need the full timestamp info to be able to set the correct order for them.
Agree about the UTC comment but our QA people, when querying the data with SE16N, would prefer to have it in local time (for the record, it is a constant UTC-4 for us, so there is no worry about DST times).
Thanks again,
Luis
2023 Jan 05 5:57 PM
Considering that you want to subtract 4 hours to the UTC timestamp, a workaround would be to subtract 14400 seconds with cl_abap_tstmp=>subtractsecs:
DATA(tstmp) = CONV TZNTSTMPL( '20230105130756.0372170' ).
data(hours) = 4.
data(secs) = hours * 3600.
tstmp = cl_abap_tstmp=>subtractsecs( EXPORTING tstmp = tstmp secs = secs ).
ASSERT tstmp = '20230105090756.0372170'.
As you say you want it to display the time to the user via SE16, a better solution would be to adapt the conversion exit TSTLC (display UTC time in user's time zone), so that it also displays the microseconds.
2023 Jan 05 6:46 PM
Sandra.
The conversion exit is exactly what we need!!
Thanks,
Luis