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 calculate from & to weekend dates based on system date

Former Member
0 Kudos

Hi friends,

Can any one let me know how to calculate from and to weekend dates based on the current system date. ASAP

1 ACCEPTED SOLUTION

former_member588853
Active Contributor
0 Kudos

HI,

the below Function module gives you the first and last day of the week for the date given..

HRWPC_BL_DATES_WEEK_INTERVAL

Is this the thing you need?

reward points if useful

regards,

nazeer

7 REPLIES 7

Former Member
0 Kudos

hi Lavanya,

Try <b>DATE_GET_WEEK</b>

Regards,

Santosh

Former Member
0 Kudos

Hi,

One way I can think of for this that u get to know the day based on the system date. Then put the conditions baesd on the day. e.g. Say if the day comes out to be Wednesday: then the week start date will be sy-datum - 3 and the weekend date will be sy-datum + 3.

U can use FM DATE_TO_DAY to get the day on current date.

Hope it helps.

Regards,

Himanshu

Message was edited by:

Himanshu Aggarwal

Former Member
0 Kudos

hi lavanya,

pls try this.

DATA : day LIKE SCAL-INDICATOR.
DATA: attr LIKE TABLE OF CASDAYATTR WITH HEADER LINE.
CALL FUNCTION 'DATE_COMPUTE_DAY'
  EXPORTING
    date          = sy-datum
 IMPORTING
   DAY           = day
          .
WRITE : day.
 
 
CALL FUNCTION 'DAY_ATTRIBUTES_GET'
 EXPORTING
   DATE_FROM                        = SY-DATUM
   DATE_TO                          = SY-DATUM
   LANGUAGE                         = SY-LANGU
  TABLES
    day_attributes                   = attr
          .
 
 
WRITE : attr-weekday_l.

Rgds

Reshma

former_member588853
Active Contributor
0 Kudos

HI,

the below Function module gives you the first and last day of the week for the date given..

HRWPC_BL_DATES_WEEK_INTERVAL

Is this the thing you need?

reward points if useful

regards,

nazeer

Former Member
0 Kudos

Hi,

Assuming that you are trying to find days that are not working days, you could use FMs in the function group SCAL.

Here, as an example, is a FORM for something related. It calculates the number of working days in a financial period. Note the program comments.

----


FORM calc_workd .

  • Note that factorydates are a day-numbers, assigned sequentially to

  • working days only. So typically the number for a Monday is one more

  • than the number for the Friday of the previous week.

clear: from_date, to_date.

  • find the factorydate of the first working day on/after period start

CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'

EXPORTING

CORRECT_OPTION = '+' "after

DATE = period-stdat

FACTORY_CALENDAR_ID = 'GB'

IMPORTING

FACTORYDATE = from_date

EXCEPTIONS

CALENDAR_BUFFER_NOT_LOADABLE = 1

CORRECT_OPTION_INVALID = 2

DATE_AFTER_RANGE = 3

DATE_BEFORE_RANGE = 4

DATE_INVALID = 5

FACTORY_CALENDAR_NOT_FOUND = 6

OTHERS = 7.

  • find the factorydate of the first working day on/before period end

CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'

EXPORTING

CORRECT_OPTION = '-' "before

DATE = period-endat

FACTORY_CALENDAR_ID = 'GB'

IMPORTING

FACTORYDATE = to_date

EXCEPTIONS

CALENDAR_BUFFER_NOT_LOADABLE = 1

CORRECT_OPTION_INVALID = 2

DATE_AFTER_RANGE = 3

DATE_BEFORE_RANGE = 4

DATE_INVALID = 5

FACTORY_CALENDAR_NOT_FOUND = 6

OTHERS = 7.

  • number of working days (inclusive)

if to_date is initial or from_date is initial.

  • If one or both of the above function calls failed, then set the

  • number of working days to zero, which can appear in the ALV

  • as blank.

clear period-workd.

else.

period-workd = to_date - from_date + 1.

endif.

ENDFORM. " calc_workd

----


Former Member
0 Kudos

Hi Lavanya,

HR_99S_INTERVAL_BETWEEN_DATES is the Function Module. Using this we can easily calculate the Days, Weeks, Months and years also.

Consider This Simple Example.

DATA : DATE1 LIKE SY-DATUM,

DATE2 LIKE SY-DATUM,

DAYS1 TYPE I,

WEEKS1 TYPE I,

MONTHS1 TYPE I,

YEARS1 TYPE I.

DATE1 = 01/01/2005..

DATE2 = SY-DATUM.

CALL FUNCTION 'HR_99S_INTERVAL_BETWEEN_DATES'

EXPORTING

BEGDA = DATE1

endda = DATE2

IMPORTING

DAYS = DAYS1

WEEKS = WEEKS1

MONTHS = MONTHS1

YEARS = YEARS1.

Write : Days1, Weeks1, Years1.

Thanks.

reward If Helpful.

Former Member
0 Kudos

Hi,

try this:

DATA: I TYPE I.

DATA: WOTNR TYPE P.

DATA: SUNDAY LIKE SY-DATUM.

DATA: SUTTER LIKE SY-DATUM.

*

CALL FUNCTION 'DAY_IN_WEEK'

EXPORTING

DATUM = SY-DATUM

IMPORTING

WOTNR = WOTNR.

*

I = 7 - WOTNR.

SUNDAY = SY-DATUM + I.

SUTTER = SUNDAY - 1.

*

WRITE: / 'Sutterday:', SUTTER.

WRITE: / 'Sunday :', SUNDAY.

Regards, Dieter