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

Date conversion to key figure format

Former Member
0 Likes
1,672

Hi all,

I am looking at a sample code that converts a date into a number format ( that is generally achieved by using the DATE() formula in excel ). For example '12/2/2011' would be '40879'.

How could we achieve this ?

Regards

Snehith

1 ACCEPTED SOLUTION
Read only

roberto_vacca2
Active Contributor
0 Likes
1,134

Hi..

We know that Excel manages dates as serial numbers.

This means that: integer 1 is January 01/01/1900 and integer 2,958,465 is December 31/12/9999. This serial number system (1 to 2,958,465) is referred as Excel Date-Time Code...

So if you do something like this:

DATA: dat TYPE sy-datum.

DATA: cnumlow TYPE i,

datlow TYPE sy-datum VALUE '18991230'. "I think you get 2 days too much with this conversion, i.e. the epoch date would have to be moved back to DateTime(1899, 12, 30). This is due to Excel's leap year bug I assume

dat = '20090505'.

write dat.

cnumlow = dat - datlow.

write cnumlow.

You should see serial number value of 05/05/2009 in cnumlow that is 39938..

Hope to help, bye!

4 REPLIES 4
Read only

Former Member
0 Likes
1,134

Hi Snehith,

Excel computes the days elapsed from January 1st, 1900.

So you could just use function module ISB_DAYS_BETWEEN_TWO_DATES with IP_DATE_FROM = '01.01.1900'.

I hope this helps. Kind regards,

Alvaro

Read only

0 Likes
1,134

Hello Alvaro Vidal-Abarca ,

Can you explan what parameter that we need to pass for the field "IP_SZBMETH".

I am not getting proper results.

Thanks,

Greetson

Read only

0 Likes
1,134

Hi Greetson,

you may populate IP_SZBMETH = '0'.

Kind regards,

Alvaro

Read only

roberto_vacca2
Active Contributor
0 Likes
1,135

Hi..

We know that Excel manages dates as serial numbers.

This means that: integer 1 is January 01/01/1900 and integer 2,958,465 is December 31/12/9999. This serial number system (1 to 2,958,465) is referred as Excel Date-Time Code...

So if you do something like this:

DATA: dat TYPE sy-datum.

DATA: cnumlow TYPE i,

datlow TYPE sy-datum VALUE '18991230'. "I think you get 2 days too much with this conversion, i.e. the epoch date would have to be moved back to DateTime(1899, 12, 30). This is due to Excel's leap year bug I assume

dat = '20090505'.

write dat.

cnumlow = dat - datlow.

write cnumlow.

You should see serial number value of 05/05/2009 in cnumlow that is 39938..

Hope to help, bye!