How to get day number from date in abap?

I need to convert a date in the format "MM / DD / YYYY" to a number that says what day of the year it is. IE '01 / 01 / YYYY '= 1 and '12 / 31 / YYYY' = 365. Is there a built-in function for this in ABAP? I tried google search but I could not find any functions that did this

+3


source to share


3 answers


It is absolutely not necessary to rely on any functional module that may or may not be on your system. Just use the basic built-in language elements:



DATA: l_my_date TYPE d, " note that the data type D is YYYYMMDD 
      l_jan_01  TYPE d, " This will be jan 1 of the needed year
      l_day     TYPE i.

l_my_date = ...whatever... 
l_jan_01 = l_my_date. 
l_jan_01+4 = '0101'. " or any other means to get the first day of the year. 
l_day = l_my_date - l_jan_01 + 1.    

      

+3


source


Here you go in one line of code:



DATA(g_day) = p_date - CONV d( p_date(4) && '0101' ) + 1.

      

+3


source


You can use this function module: HR_AUPBS_MONTH_DAY

.

You need to pass in a start date and an end date and it will return the number of days in between (which is what you want):

CALL FUNCTION 'HR_AUPBS_MONTH_DAY'
  EXPORTING BEG_DA     = P_BEGDA    " Here you should put the first day of the year
            END_DA     = P_ENDDA    " Here you put the date
  IMPORTING NO_CAL_DAY = P_CAL_DAY. " This is what you want

      

+2


source







All Articles