09-08-2007 1:39 PM
Hi Experts,
Is there any FM for date calculation.
I have one scenario
In selection screen we have on Select Option field Date.
If I put the some ranges in Date (selection field ) , we need to calculate how many dates in between.
Could you please help me.
Thanks and regards,
Amjad Hussain,
09-08-2007 1:49 PM
Hi,
Please use the code given below :
data : date_diff type p, earliest type C, timediff type p.
data : c_new type t, d_new type t.
selection-screen begin of block b1 with frame.
SELECT-OPTIONS: date FOR sy-datum.
selection-screen end of block b1.
CALL FUNCTION '/SDF/CMO_DATETIME_DIFFERENCE'
EXPORTING
date1 = date-low
time1 = c_new
date2 = date-high
time2 = d_new
IMPORTING
DATEDIFF = date_diff
TIMEDIFF = timediff
EARLIEST = earliest
EXCEPTIONS
INVALID_DATETIME = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
write : / date_diff.
I hope, it can help you,
Reward points, if helpful,
Sandeep Kaushik
09-08-2007 1:49 PM
Hi,
Please use the code given below :
data : date_diff type p, earliest type C, timediff type p.
data : c_new type t, d_new type t.
selection-screen begin of block b1 with frame.
SELECT-OPTIONS: date FOR sy-datum.
selection-screen end of block b1.
CALL FUNCTION '/SDF/CMO_DATETIME_DIFFERENCE'
EXPORTING
date1 = date-low
time1 = c_new
date2 = date-high
time2 = d_new
IMPORTING
DATEDIFF = date_diff
TIMEDIFF = timediff
EARLIEST = earliest
EXCEPTIONS
INVALID_DATETIME = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
write : / date_diff.
I hope, it can help you,
Reward points, if helpful,
Sandeep Kaushik
09-08-2007 1:52 PM
Hi mohammed,
You can use the following FM
CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
EXPORTING
DATE1 = higher date
DATE2 = lower date
OUTPUT_FORMAT = '02'
IMPORTING
DAYS = W_DAYS
EXCEPTIONS
INVALID_DATES_SPECIFIED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Based on output_format you can get years/days/months combination
OUTPUT_FORMAT = '02' will give you the days only as requested
Other function modules are also available like
FIMA_DAYS_AND_MONTHS_AND_YEARS
FIMA_DAYS_BETWEEN_TWO_DATES
Reward if helpful
Regards
Byju
09-08-2007 2:12 PM
Use below FM :
Just use DAY_ATTRIBUTES_GET function module and give DATE_FROM and DATE_TO it it, and it will return an internal table with all the dates in between. It gives you more information than you need, but it is the easiest.
If you use other FM then if date from and date to are in same year ,then it works .
if dates are not in same year,then it will not work.
Try to use DAY_ATTRIBUTES_GET -> it gives the all information.
Thanks
Seshu