05-25-2007 2:00 PM
Is there a smooth way to convert a timestamp containing local time to UTC time?
The statement:
CONVERT TIME STAMP time_stamp TIME ZONE tz
INTO [DATE dat] [TIME tim]
[DAYLIGHT SAVING TIME dst].
Consideres time_tamp to be UTC time and then tries to convert it to the time zone specified in tz. What I would like to have done is the opposite, to have time_stamp represent the local time and then convert it back to UTC.
TIA!
/Armin
05-25-2007 4:12 PM
Hi Armin.
Just turn your statement and you will be fine
DATA: date TYPE sydatum VALUE '20070525',
time TYPE syuzeit VALUE '173030',
cet TYPE tzonref-tzone VALUE 'CET',
utc TYPE tzonref-tzone VALUE 'UTC',
tstp TYPE timestamp.
CONVERT DATE date TIME time INTO TIME STAMP tstp TIME ZONE cet .
The output will be 15:30:30 at 25th of May 2007.
I used CET as example, just use the timezone your date is representing. The result is formatted as UTC.
Actually if you only have the timestamp, for this solution you have to convert it into date/time first.
Use
CONVERT TIME STAMP tstp TIME ZONE utc INTO DATE date TIME time.
to do so.
Regards,
Timo.
05-25-2007 2:07 PM
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'.
write : / tstamp_UTC.
05-25-2007 2:35 PM
Sorry, but it doesn't work.
It just converts from UTC to UTC, ergo nothing changes, the timestamp remains the same!
Also
d = tstamp+0(8).
t = tstamp+8(8).
is not possible since you can't reference timestamp like that!
05-25-2007 4:12 PM
Hi Armin.
Just turn your statement and you will be fine
DATA: date TYPE sydatum VALUE '20070525',
time TYPE syuzeit VALUE '173030',
cet TYPE tzonref-tzone VALUE 'CET',
utc TYPE tzonref-tzone VALUE 'UTC',
tstp TYPE timestamp.
CONVERT DATE date TIME time INTO TIME STAMP tstp TIME ZONE cet .
The output will be 15:30:30 at 25th of May 2007.
I used CET as example, just use the timezone your date is representing. The result is formatted as UTC.
Actually if you only have the timestamp, for this solution you have to convert it into date/time first.
Use
CONVERT TIME STAMP tstp TIME ZONE utc INTO DATE date TIME time.
to do so.
Regards,
Timo.
05-17-2019 3:41 PM
Hi Timo, thank you very much for your valuable post!
As far as I have understood, if one has only a timestamp, we have to generate Date und Time first (with the last stated CONVERT instruction) and then convert again with the first stated CONVERT instruction. Is this right?
When converting for the second time, does ABAP interpret Date and Time that way that it already has been converted to UTC before? What I mean is: Don't we convert twice with UTC, so that the 2nd conversion considers a local time?
05-20-2019 8:05 AM
05-29-2007 8:33 AM
05-29-2007 8:34 AM
10-15-2021 3:52 PM
You have to go through a few conversions, but eventually it works.
* Target: Get latest timestamp from ADSO and give it to variable. But due summertime issues the time gets two hours extra when opening the query. The format in BW is 14 NUMC and cannot easily be converted. So I firstly retrieved the timestamp, than converted into a timestamp added with a timezone. Then converted UTC to CET and than back into the output of the variable. Its a bit a mess, but it works.
IF i_step = 1.
DATA: max_tstamp TYPE /bi0/oitctlstload,
time_stamp TYPE timestamp,
cet TYPE tzonref-tzone VALUE 'CET',
utc TYPE tzonref-tzone VALUE 'UTC',
tz TYPE ttzz-tzone,
date TYPE sydatum,
time TYPE syuzeit.
SELECT SINGLE MAX( tctlstload ) FROM /bic/azldatmon2 INTO max_tstamp.
tz = 'CET'.
time_stamp = max_tstamp.
CONVERT TIME STAMP time_stamp TIME ZONE tz
INTO DATE DATA(dat) TIME DATA(tim)
DAYLIGHT SAVING TIME DATA(dst).
CONVERT TIME STAMP time_stamp TIME ZONE utc INTO DATE date TIME time.
CONVERT DATE date TIME time INTO TIME STAMP time_stamp TIME ZONE cet.
max_tstamp = time_stamp.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
l_s_range-low = max_tstamp.
APPEND l_s_range TO e_t_range.
ENDIF.