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

counting days between dates

Former Member
0 Likes
763

hi friends, i need to calculate the days lapsed between, when the idoc was created and when it showed error.

so i thought, i need to extract date1 from a table edids when status =50 (ie. idoc created ),

and then date2 should be picked up as soon as the status of this idoc becomes 51 ( ie. error idoc).

for this i thought of doing like below:

data: date1 type sy-datum,

date2 type sy-datum.

select * from edids into table int_edids

where docnum = t_edidc-docnum

and order by countr.

loop at int_edids.

if t_edidc-status = 50.

date1= int_edids-credat.

endif.

if t_edidc-status = 51.

date2 = int_edids-credat.

exit.

endif.

endloop.

lapsed_days = date1 - date2.

will this statement work.

is there a better way of doing this ?

can some one help me with this ?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
719

It should work ,looks like correct statement.

Thanks

Seshu

5 REPLIES 5
Read only

gopi_narendra
Active Contributor
0 Likes
719

Check these FM:

FIMA_DAYS_AND_MONTHS_AND_YEARS

Test the FM with the parameters as

 Import parameters               Value
 I_DATE_FROM                     12.08.2007
 I_DATE_TO                       15.08.2007
 I_FLG_SEPARATE                  X
 " You wull get the output as
 Export parameters               Value
 E_DAYS                          3
 E_MONTHS                        0
 E_YEARS                         0

Regards

Gopi

Read only

Former Member
0 Likes
720

It should work ,looks like correct statement.

Thanks

Seshu

Read only

former_member196280
Active Contributor
0 Likes
719

Use this function module to count the number of days...

/SDF/CMO_DATETIME_DIFFERENCE

Pass date 1 and date 2 and get the difference in dates.

Regards,

SaiRam

Read only

Former Member
0 Likes
719

hai Sanjana,

Use the Function Module ISHMED_CALC_DATE_TIME_DIFF

Import parameters Value

I_BEGDT 01.01.2007

I_BEGTM 00:00:00

I_ENDDT 01.08.2007

I_ENDTM 00:00:00

Changing parameters Value

CR_ERRORHANDLER

Export parameters Value

E_DIFF_DAY 212

E_ENDDT_EARLY

E_RC 0

U can find the time diff also from this function module.

OR OR OR OR

you Use SD_DATETIME_DIFFERENCE

DATE1 01.01.2007

TIME1 12:00:00

DATE2 01.08.2007

TIME2 10:00:00

Export parameters Value

DATEDIFF 211

TIMEDIFF 22

EARLIEST 1

Reward Points If Use Full

Thanks & Regards.

Shiva

Thanks & Regards,

Shiva

Read only

Former Member
0 Likes
719

Hi,

Try with this code:

DATA: EDAYS LIKE VTBBEWE-ATAGE,

EMONTHS LIKE VTBBEWE-ATAGE,

EYEARS LIKE VTBBEWE-ATAGE.

PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,

TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.

call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

exporting

i_date_from = FROMDATE

i_date_to = TODATE

  • I_FLG_SEPARATE = ' '

IMPORTING

E_DAYS = EDAYS

E_MONTHS = EMONTHS

E_YEARS = EYEARS.

WRITE:/ 'Difference in Days ', EDAYS.

WRITE:/ 'Difference in Months ', EMONTHS.

WRITE:/ 'Difference in Years ', EYEARS.

INITIALIZATION.

FROMDATE = SY-DATUM - 60.

Regards,

Bhaskar