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: 

Timestampl too short after CONVERT DATE TIME

sapuserpl
Explorer
0 Kudos
755

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

9 REPLIES 9

raymond_giuseppi
Active Contributor
0 Kudos
649

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

  • display '2023‑12‑01T14:23:26,8633200' and '2023‑12‑01T15:23:26,8633200'
  • in debug '20231201142326.8633200'

0 Kudos
649

But your proposal return bad time, moved back by an 1 hour.

0 Kudos
649

I corrected the display to adapt to system time zone.

  • The statement GET TIME STAMP provides by definitin an UTC time zone.
  • If you want another type of timestamp, consider methods of class CL_ABAP_TSTMP.

0 Kudos
649

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 "."

0 Kudos
649

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

Sandra_Rossi
Active Contributor
0 Kudos
649

You are mixing two things:

  1. one hour difference because of time zones: nothing is "bad", it's just because you don't use the right time zones, or you don't understand how it works in SAP...
  2. how to get the microseconds (does not depend on time zones): I don't get what you want to achieve, you can't get the microseconds with CONVERT DATE TIME because the source time doesn't contain the microseconds.

Please clarify your question.

Clemenss
Active Contributor
649

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

sapuserpl
Explorer
0 Kudos
649

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 ?

Sandra_Rossi
Active Contributor
0 Kudos
649

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.