Application Development and Automation 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: 
Read only

timestamp to date conversion

Former Member
0 Likes
47,103

I have got to get a local date from time stamp. Time stamp is of server time. And I have time zone off set. for example

20,130,927,183,711    -04:00

20,130,905,200,845    +02:00

I need to use the time zone offset to get the local date.

I was hoping I will be able to use

  CONVERT TIME STAMP my_TSTMP TIME ZONE
        tzone INTO DATE calday .

but tzone is expected in the formate of UTC-1 or UTC+2 as such.  What will be the best option to get the local date from the information I have in hand. Any suggestion will be very much appreciate.

1 ACCEPTED SOLUTION
Read only

Former Member
38,230

Hi Guys,

Thanks for all your replies. My problem was I do not have time zone in the format required. What I ended up doing was, I first offset the timestamp with the time zone information I had.

for example for this record =>

20,130,927,183,711-04:00

I subtract 4 hours from the time stamp. And convert the resulting timestamp (which is now a local date and time ) into date with 'UTC' as a time zone. It gives me a local date.

10 REPLIES 10
Read only

Former Member
0 Likes
38,230

This message was moderated.

Read only

sivaganesh_krishnan
Contributor
0 Likes
38,230

Hi Sophie,

Instead of passing the time of different places directly , just refer table TTZZ . This table contains all the timezone , select the zone for which ur coding and pass it like this.

DATA:

  s_tst LIKE tzonref-tstamps,
  l_tst LIKE tzonref-tstampl,
  tzone LIKE tzonref-tzone,
d TYPE D ,
t TYPE T .


GET TIME STAMP FIELD s_tst.         "Short form
GET TIME STAMP FIELD l_tst.         "Long form
tzone = 'ALA  '.                                   "Specify the time zone here.. refer TTZZ table

CONVERT TIME STAMP l_tst TIME ZONE tzone INTO
        DATE d TIME t.


"timestamps - short and long
WRITE: / s_tst TIME ZONE tzone,
              / l_tst TIME ZONE tzone.

WRITE:/ 'After conversion'.

WRITE:/  d,      " 12/24/1997

    /, (8t.      " 23:55:00

Hope this Helps

Regards,

Sivaganesh

Read only

0 Likes
38,230

I should use your solution,and for tzone I should use sy-zynlo.

Best,

Sander

Read only

anshu_lilhori
Active Contributor
0 Likes
38,230

Hi,

You may try to use the following function module;

CONV_UTIL_ADD_DATE_AND_TIME

Hope that helps.

Regards,

AL

Read only

Former Member
0 Likes
38,230

HI,

DATA : v_timestamp TYPE timestampl,

        output  TYPE string.

GET TIME STAMP FIELD v_timestamp.

WRITE : v_timestamp.

output |{ v_timestamp TIMESTAMP = ISO }|."TIMEZONE = 'UTC   ' }|.

WRITE / output.

OR this should work for you.

DATA : v_timestamp TYPE timestampl,

        v_timestamp1 TYPE timestampl,

        output  TYPE string,

        date TYPE datum,

        time TYPE tims.

DATA : time_zone TYPE tzonref-tzone value 'INDIA'.

GET TIME STAMP FIELD v_timestamp.

WRITE : v_timestamp.

CONVERT TIME STAMP v_timestamp TIME ZONE time_zone INTO date date Time time.

write :date DD/MM/YYYY .

WRITE : time.


Thanks & Regards

Priyesh Shah


Message was edited by: Priyesh Shah

Read only

rosenberg_eitan
Active Contributor
0 Likes
38,230

Hi,

Try this:

Regards.

REPORT  y_r_eitan_test_09_03 .



*----------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK block02 WITH FRAME .



PARAMETERS: p_date_f TYPE sydatum OBLIGATORY DEFAULT sy-datum .

PARAMETERS: p_time_f TYPE syuzeit OBLIGATORY DEFAULT sy-uzeit .



SELECTION-SCREEN SKIP .



PARAMETERS: p_zone_f TYPE ttzz-tzone OBLIGATORY DEFAULT sy-zonlo .

PARAMETERS: p_zone_t TYPE ttzz-tzone OBLIGATORY DEFAULT 'JAPAN' .



SELECTION-SCREEN END OF BLOCK block02 .

*----------------------------------------------------------------------*



AT SELECTION-SCREEN .

  PERFORM at_selection_screen_input  .



*----------------------------------------------------------------------*

FORM at_selection_screen_input .



  DATA: stamp_1 TYPE timestamp .



  CONVERT DATE p_date_f TIME p_time_f

    INTO TIME STAMP stamp_1 TIME ZONE p_zone_f .



  IF sy-subrc NE 0 .

    MESSAGE e212(rd) .

  ENDIF .



  DATA: dst TYPE c LENGTH 1 .

  DATA: datum TYPE sydatum .

  DATA: uzeit TYPE syuzeit .



  CONVERT TIME STAMP stamp_1 TIME ZONE p_zone_t

    INTO DATE datum TIME uzeit DAYLIGHT SAVING TIME dst.



  MESSAGE s000(ooWITH 'Time at' p_zone_t datum uzeit .



ENDFORM .                    "at_selection_screen_input

*----------------------------------------------------------------------*

Read only

Former Member
0 Likes
38,230

Hi Sophie,

You can try this:

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

Regards,

Ashish Kumar

Read only

Former Member
0 Likes
38,230

HI,

Try This..

CONVERT TIME STAMP my_TSTMP TIME ZONE ' UTC '
     INTO DATE date TIME time.

Regards,

Charan M.

Read only

0 Likes
38,230

Hi,

Charan has the right idea.  You need to convert the timestamp you have (e.g. 20,130,927,183,711    -04:00) to UTC and then convert that to the local time zone.

If your report is dependent upon a plant code you may not be able to us sy_zynlo. If this is the case you may need to create a separate configuration table with plant codes and time zones.

Regards,

Steve

Read only

Former Member
38,231

Hi Guys,

Thanks for all your replies. My problem was I do not have time zone in the format required. What I ended up doing was, I first offset the timestamp with the time zone information I had.

for example for this record =>

20,130,927,183,711-04:00

I subtract 4 hours from the time stamp. And convert the resulting timestamp (which is now a local date and time ) into date with 'UTC' as a time zone. It gives me a local date.