2023 Dec 01 1:03 PM
Hello Experts,
I need long format timestampl after dot. At the beginnig I used command "get time stamp field" but the time was bad because was moved back by an 1 hour. I changed to "convert date time" but then timestampl is too short after dot.
GET TIME STAMP FIELD lv_tsl.
DATA: lv_tz TYPE sy-zonlo VALUE 'UTC',
<br> lv_tsl TYPE timestampl.<br>
<br> CONVERT DATE sy-datum TIME sy-uzeit INTO TIME STAMP lv_tsl TIME ZONE lv_tz.
lv_tsl is to short after "." e.g. 20231201135009.0000000
Correct format is e.g. 20231201125033.6795980
2023 Dec 01 1:32 PM
If you convert from system date and time, don't expect decimals in the result.
DATA: tsl TYPE timestampl,
tz TYPE timezone.
GET TIME STAMP FIELD tsl.
CALL FUNCTION 'GET_SYSTEM_TIMEZONE'
IMPORTING
timezone = tz.
cl_demo_output=>new(
)->write( |{ tsl TIMESTAMP = ISO
TIMEZONE = 'UTC' }|
)->write( |{ tsl TIMESTAMP = ISO
TIMEZONE = tz }|
)->display( ).
BREAK-POINT.
result
2023 Dec 01 1:58 PM
2023 Dec 01 2:25 PM
I corrected the display to adapt to system time zone.
2023 Dec 01 2:40 PM
Nothing changed, only the command
CONVERT DATE sy-datum TIME sy-uzeit INTO TIME STAMP lv_tsl TIME ZONE lv_tz.
gave me correct time but without decimals after "."
2023 Dec 01 3:25 PM
Only statement GET TIME STAMP will provide the decimal pat after seconds and only in UTC time stamp
If for some reason you want an internal format for another time stamp, and cannot use display options, then look at methods of class CL_ABAP_TSTMP
2023 Dec 01 4:33 PM
You are mixing two things:
Please clarify your question.
2023 Dec 01 9:01 PM
GET TIME STAMP FIELD
provides a timestamp in UTC (Universal Time Coordinated) completely independent of local time, summer time or whatever. Is has always the same value all over the planet.
Convert local date time can not have any digits right if decimal point because the smallest unit is one second.
Timestamp is exact millisecond. You may convert it to local date and time in your time zone sy-zonlo - losing the millisconds.
Just let us know what you want to achieve.
Clemens
2023 Dec 04 9:10 AM
I want to achieve timestamp in long format (type timestampl) with correct time. I know that utc format time is on the short format without miliseconds. Is it only one way by add artificial miliseconds copied from function GET TIME STAMP FIELD tsl ?
2023 Dec 04 1:59 PM
Your question was unclear since the beginning.
Now, I understand that you want the current time with microseconds (not milliseconds, right?) in the UTC "timezone".
GET TIME STAMP FIELD returns the current time with microseconds in UTC so no need to convert it.
Please clarify your question.