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 Calc

former_member184495
Active Contributor
0 Likes
777

hi,

how would i calculate the number of weeks left for that fiscal year...

say for instance, i have auctioned an asset in the month of August-2006 (8th month),

now till december 31 there are 22 weeks left,

so is there a FM which could calculate this for me ?

cheers,

Aditya.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
732

The easiest way is to calculate the days between year end and the required date. Later divide the output by 7 would give you the number of weeks.

in your example.---logic

lyrend = 31/12/2006.

ldate = sy-datum.

ldays = lyrend - ldate.

lweeks = ldays DIV 7.

Regards

Anurag

5 REPLIES 5
Read only

dani_mn
Active Contributor
0 Likes
732

HI,

check this FM

<b>HR_IE_NUM_PRSI_WEEKS</b>

this will return the complete weeks between two dates.

so you have to add 2 more to get half weeks at begin and end.

Regards,

HRA

Message was edited by: HRA

Read only

Former Member
0 Likes
732

Hi aditya,

1. use the FM

DATE_GET_WEEK

2. It will give the WEEK NUMBER

(when we give any date as input)

3. so for august,

we can construct some date (using 01 as day)

and pass it to the FM.

It will return 200631 (week number)

4. For 31.12.2006, it will return 200652

5. 200652 MINUS 200631 = 21

( u may have to make some modifications/adjustments)

regards,

amit m.

Read only

Former Member
0 Likes
733

The easiest way is to calculate the days between year end and the required date. Later divide the output by 7 would give you the number of weeks.

in your example.---logic

lyrend = 31/12/2006.

ldate = sy-datum.

ldays = lyrend - ldate.

lweeks = ldays DIV 7.

Regards

Anurag

Read only

Former Member
0 Likes
732

data: duration_in_days type i.

parameters: s_date type sy-datum,

e_date type sy-datum.

call function 'DURATION_DETERMINE'

exporting

factory_calendar = 'P6'

importing

duration = duration_in_days

changing

start_date = s_date

end_date = e_date

exceptions

factory_calendar_not_found = 1

date_out_of_calendar_range = 2

date_not_valid = 3

unit_conversion_error = 4

si_unit_missing = 5

parameters_not_valid = 6

others = 7.

IF SY-SUBRC = 0.

duration_in_days = duration_in_days / 7.

to get no of weeks

ENDIF.

Read only

Former Member
0 Likes
732

get the week number of december 31 of this year.(12312006)using fm 'GET_WEEK_INFO_BASED_ON_DATE'.

get weeknumber of 1st of next month using the fm 'GET_WEEK_INFO_BASED_ON_DATE'.

get the difference.

concatenate '12' '31' sy-datum+4(4) into v_dec_31.

call function 'GET_WEEK_INFO_BASED_ON_DATE'

exporting

date = v_dec_31

importing

week = week1.

v_next_month = sy_datum+0(2) + 1.

concatenate v_next_month '01' sy-datum+4(4) into v_next_month_1st.

call function 'GET_WEEK_INFO_BASED_ON_DATE'

exporting

date = v_next_month_1st

importing

week = week2.

v_no_of_weeks_left = week24(2) - week14(2).

Regards,

ravi