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

Function to convert timestamps into milliseconds

Former Member
0 Likes
4,907

Hi,

Does SAP have a function module which can read in a date/timestamp and output that time in milliseconds (a long integer starting from 1st January 1970)?

Many thanks in advance,

Peter

1 ACCEPTED SOLUTION
Read only

andreas_mann3
Active Contributor
0 Likes
2,556

try:

PARAMETERS:d2 TYPE sy-datum DEFAULT sy-datum,

d1 TYPE sy-datum default '19700101'.

data sec_day TYPE i . "ms per day

DATA : d TYPE i.

DATA result TYPE f.

DATA rp(16) type p decimals 0.

AT SELECTION-SCREEN ON d2.

IF d2 LE d1.

MESSAGE e001(00) WITH 'date must be greater than 1970/01/01'.

ENDIF.

START-OF-SELECTION.

sec_day = 24 * 60 * 60 * 1000.

d = d2 - d1.

rp = result = d * sec_day.

WRITE: / d2, d1, d, / result, rp.

hope that helps

Andreas

Edited by: Andreas Mann on Apr 10, 2008 3:37 PM

Hi,

Does SAP have a function module which can read in a date/timestamp and output that time in milliseconds (a long integer starting from 1st January 1970)?

Many thanks in advance,

Peter

3 REPLIES 3
Read only

Former Member
0 Likes
2,556

HHMMSSZZZ (H=hours, M=minutes, S=seconds, Z=milliseconds).

Use FM CRMBW_GET_TIME

You can use GET TIME keyword and there you can specify the format that you want.

DATA: BEGIN OF wa,

...

time_stamp TYPE timestampl,

...

END OF wa.

...

GET TIME STAMP FIELD wa-time_stamp.

INSERT dbtab FROM wa.

Regards,

Santosh

Read only

andreas_mann3
Active Contributor
0 Likes
2,557

try:

PARAMETERS:d2 TYPE sy-datum DEFAULT sy-datum,

d1 TYPE sy-datum default '19700101'.

data sec_day TYPE i . "ms per day

DATA : d TYPE i.

DATA result TYPE f.

DATA rp(16) type p decimals 0.

AT SELECTION-SCREEN ON d2.

IF d2 LE d1.

MESSAGE e001(00) WITH 'date must be greater than 1970/01/01'.

ENDIF.

START-OF-SELECTION.

sec_day = 24 * 60 * 60 * 1000.

d = d2 - d1.

rp = result = d * sec_day.

WRITE: / d2, d1, d, / result, rp.

hope that helps

Andreas

Edited by: Andreas Mann on Apr 10, 2008 3:37 PM

Read only

Former Member
0 Likes
2,556

Many thanks Andreas!

Just one thing - I make the number of milliseconds in a day 86400000

(10006060*24) - one less zero

Peter