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: 

How to find 3rd friday of the month

Former Member
0 Kudos
1,148

Hi all,

I have a requirement to calculate the 3rd friday of the current month.

Calculated payment date must be postponed to the date of 3rd Friday of the current month.

If 3rd Friday of the month < Calculated Payment date, then 3rd Friday of next month will be given in this field.

This is my requirement. Is there any function module to find the perticular day in the month.

Thanks in advance.

Thansk & Regards,

Rao N

4 REPLIES 4

Former Member
0 Kudos
156

Venkat,

I don't think there is any Function module which directly outputs the day.

But there can be convoluted logic, you can make.

Use the Function module 'DATE_COMPUTE_DAY', Pass the date and get the Day of the week as output. ( Here the output will be (1 for Monday, 2 for tueday and ....7 for Sunday).

You can build your logic like below.

Pass the date to this function module and get the day out. The 3rd time you get the Day as '5' will be your 3rd friday of the month.

Build your logic as below.

Date = Sy-datum.

Do n times.

CALL FUNCTION 'DATE_COMPUTE_DAY'

EXPORTING DATE = DATE

IMPORTING DAY = WEEKDAY.

If

The 3rd time you get the Day as '5' will be your 3rd friday of the month.

Exit from the loop.

endif

increment date by 1

End Do.

Hope this helps

Vinodh Balakrishnan

Former Member
0 Kudos
156

Hi Venkat,

Check these function modules.These might be of help for you.

DATE_GET_WEEK

ISP_GET_WEEKDAY_NAME

'DAY_ATTRIBUTES_GET'

GET_WEEK_INFO_BASED_ON_DATE

see these FM's related to calender. they may help you.

WEEK_GET_FIRST_DAY

This function module returns the first day of the week passed. (This is always a Monday, regardless of whether it is a working day or a holiday.)

FACTORYDATE_CONVERT_TO_DATE

This function module returns the calendar date for the factory date and the factory calendar passed.

DATE_CONVERT_TO_FACTORYDATE

This function module returns the factory date for the date and factory calendar passed. You can specify with a parameter whether the next or the previous working day is returned if the day is not a working day.

RP_CALC_DATE_IN_INTERVAL

Add/subtract years/months/days from a date

SD_DATETIME_DIFFERENCE

Give the difference in Days and Time for 2 dates

MONTH_PLUS_DETERMINE

Add or subtract months from a date. To subtract a month, enter a negative value for the 'months' parameter.

DATE_CHECK_PLAUSIBILITY

Check to see if a date is in a valid format for SAP. Works well when validating dates being passed in from other systems.

DATE_CONV_EXT_TO_INT

Conversion of dates to SAP internal format e.g. '28.03.2000' -> 20000328

DATUMSAUFBEREITUNG

Format date as the user settings

MONTH_NAMES_GET

It returns all the month and names in repective language.

DATE_IN_FUTURE

Calculate a date N days in the future.

The system variable SY-FDAYW will have the day numbers from 0 to 6...(i.e. Sunday to Saturday)

0 - sunday

1- monday

2- tuesday

like above....

check sy-fdayw = 6...(for saturday)

You can also use the following method which gives the day number in the week.

CALL METHOD cl_pt_time_eval_utilities=>weekday

EXPORTING

im_date = im_date

RECEIVING

result = l_weday_number.

Check if any of these will be useful by using it along with your code.

Reward if helpful.

Regards,

Kashyap

Former Member
0 Kudos
156

You need to work around a logic to arrive at this .

The difference between first friday and the 3 rd friday is 14 days .

1.First use the start date of the month to find what day is it .

Since u have the month number and year making the date as 01 will give u the start day of the month .

DATE_COMPUTE_DAY

will give u the first friday .

check the documentation of the Fm .

This will give u the first friday of the week .

Now once u have this day confirmed then u can add the required number of days to the first firday's date i.e 14 days

and get the 3 rd fridays date .

You can use RP_CALC_DATE_IN_Interval func module to get this.

Im not on sap so i hope u can work around this logic .

Vijay.

Former Member
0 Kudos
156

Here is the complete code to handle the same.

REPORT z_3_friday_of_month.

PARAMETER : p_date LIKE sy-datum.

DATA : date LIKE scal-date,

day LIKE scal-indicator.

    • Get the day of the first day of the month.

IF p_date NE '00000000' OR p_date NE space.

*make the date to sync with the start of month.

p_date+6(2) = '01'.

date = p_date.

CALL FUNCTION 'DATE_COMPUTE_DAY'

EXPORTING

date = date

IMPORTING

day = day.

WRITE:/ 'DAY OF THE WEEK AS ', day.

CASE day.

WHEN 1. "WHEN MONDAY

ADD 4 TO date.

WHEN 2.

ADD 3 TO date.

WHEN 3.

ADD 2 TO date.

WHEN 4.

ADD 1 TO date.

WHEN 5.

ADD 0 TO date.

WHEN 6.

ADD 6 TO date.

WHEN 7.

ADD 5 TO date.

ENDCASE.

WRITE:/ sy-uline.

WRITE:/ 'FIRST FRIDAY OF THE MONTH IS ON ', date.

ADD 14 TO date .

WRITE:/ sy-uline.

WRITE:/ 'THIRD FRIDAY OF THE MONTH IS ON ', date.

ENDIF.