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: 

Calculate the days in the year

Former Member
0 Kudos

Hi Gurus,

My requirement is, If U select the date counting the days in the year.

which FM is used the calulate the days in the year (365 days)

example: if I will execute 2 feb 2008 I want display 033

because in January month 31 days are there and adding the february month 2 days it will be totally 33 days in the year.

if I Execute 15 march 2008

it will be display 075 = 31(January)29(february)15(march)

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi,

you can directly write this logic in your code itself.

check the following code.


DATA: dt1 TYPE sy-datum,
      dt2 TYPE sy-datum,
      count TYPE i.

dt2 = '20070303'.

CONCATENATE dt2(4) '0101' INTO dt1.
count = dt2 - dt1 + 1.       "count must be of type integer

WRITE count.

try using different years (leap and non leap). "count" variable will give you the correct result for all cases.

9 REPLIES 9

Former Member
0 Kudos

HI,

Use the FM and pass the Start date of the year and the Date of Execution you will get the result.

FIMA_DAYS_BETWEEN_TWO_DATES_2

Reagrds

Sumit Agarwal

Former Member
0 Kudos

Use FM SD_DATETIME_DIFFERENCE.

Former Member
0 Kudos

DAYS_BETWEEN_TWO_DATES

hi try this

it will work

sure

with regards

s.janagar

Former Member
0 Kudos

Hi,

Check the following:

HR_SGPBS_ADD_TIME_TO_DATE

HR_MX_DAYS_PER_YEAR

FIMA_DAYS_BETWEEN_TWO_DATES

Hope this will be helpful.

Regards,

P.S.Chitra

Former Member
0 Kudos

hi,

you can directly write this logic in your code itself.

check the following code.


DATA: dt1 TYPE sy-datum,
      dt2 TYPE sy-datum,
      count TYPE i.

dt2 = '20070303'.

CONCATENATE dt2(4) '0101' INTO dt1.
count = dt2 - dt1 + 1.       "count must be of type integer

WRITE count.

try using different years (leap and non leap). "count" variable will give you the correct result for all cases.

former_member585060
Active Contributor
0 Kudos

Hi,

Use this FM

HR_NL_PS_CALENDERDAYS_360

********************************************************************

Data : Num type INT4.

Data : Begdate type sy-datum, " Always make it to 1 Jan

Enddate type sy-datum. " Date for which you want to count

Begdate = '01.01.2008'.

CALL FUNCTION 'HR_NL_PS_CALENDERDAYS_360'

EXPORTING

BEGINDATUM = Begdate

EINDDATUM = Enddate

IMPORTING

KALENDERDAGEN = Num.

Write 😕 Num.

Edited by: Bala Krishna on Sep 22, 2008 3:05 PM

0 Kudos

Hi Vikram Shah ,

Thanks a lot. I gave full points also.

Former Member
0 Kudos

Hi sreedhar,

The followinf FMs will be useful.

Give the start date as year starting date.say example 01.01.2008 and end date of choice required.

FIMA_DAYS_AND_MONTHS_AND_YEARS

HR_SGPBS_YRS_MTHS_DAYS

FIMA_DAYS_BETWEEN_TWO_DATES

Can find the related FM by as follows,

In SE37 - type (star) days(star) as name of FM and press F4.

Gives u a pop up with list of FMs.

check & use the required one.

Regards,

Salini.

Edited by: satya salini on Sep 22, 2008 12:04 PM

Edited by: satya salini on Sep 22, 2008 12:06 PM

Former Member
0 Kudos

Hi,

simple use this:

data: dat1 like sy-datum.

data: dat2 like sy-datum.

data: days type i.

*

dat1 = '20080615'.

*

dat2 = dat1.

dat2+4(4) = '0101'.

days = dat1 - dat2.

*

write: / dat1, dat2, days.

*

Regards, Dieter