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 out duration between two dates

Former Member
0 Kudos

hi Buddies.....

the problem is there is no output... It shows 0 (zero) in output... Please help me to solve this problem...

thanks,

anand. S

22 REPLIES 22

Former Member
0 Kudos

Would be nice if we knew what you were doing.

But since your problem description is so vague, i'll give you a vague answer: 42.

Former Member
0 Kudos

Hi dude,

Don directly subtract two dates.

Goto SE37,

Press F4.

In the information system, under SHORT DESCRIPTION, search as follows.

DateCalculation*

or

DateTwo*.

You will find some function module to do this.

0 Kudos

And what is wrong with subtracting 2 dates?

peter_ruiz2
Active Contributor
0 Kudos

Hi Anand,

Use this Function Module

SD_DATETIME_DIFFERENCE

regards,

Peter

Former Member
0 Kudos

DAYS_BETWEEN_TWO_DATES

use this function module

Former Member
0 Kudos

Could you send me the exact coding ...?

0 Kudos

call function 'HR_HK_DIFF_BT_2_DATES'

exporting

date1 = '19950630'

date2 = '19950101'

  • OUTPUT_FORMAT = '01'

*IMPORTING

  • YEARS =

  • months = mon

  • 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.

This is my input.. But there is no output.

0 Kudos

as it was told already (by Maen), there is no reason to use FM for calculating the difference between two dates. simply:

DATA : diff TYPE i.

diff = date1 - date2.

(where both dates are TYPE datum)

0 Kudos

hi..

try giving date1 as '19950101'

date2 = '19950630'

regards,

Padma

0 Kudos

Oh boy....

Remove the comment mark before IMPORTING and DAYS

And assign a variable to DAYS.

Edited by: Maen Anachronos on Oct 9, 2008 2:42 PM

0 Kudos

>

> Could you send me the exact coding ...?

Can you send me the exact dates...?

0 Kudos

call function 'HR_HK_DIFF_BT_2_DATES'

exporting

date1 = '19950630'

date2 = '19950101'

  • OUTPUT_FORMAT = '01'

*IMPORTING

  • YEARS =

  • months = mon

  • 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.

This is my input.. But there is no output.

0 Kudos

My last try on this one...

How do you suppose to get a value BACK from the function module if you don't supply a variable to the IMPORTING part?

IMPORTING
  MONTHS = mon

instead of (see the difference?)


* IMPORTING
*     MONTHS = mon

or even

IMPORTING
  DAYS = day

And what do you need to calculate? The differnce in DAYS? MONTHS?

Edited by: Maen Anachronos on Oct 9, 2008 3:54 PM

0 Kudos

Hi,

Please first tell us in what format do you want your output. If it is the number of days alone then you can directly do a date1 - date2.

If you require in Years months days only then you need to use this FM and here is the coding.

data : w_year type <data_type_in_FM>,

w_mon type <data_type_in_FM>,

w_days type <data_type_in_FM>.

call function 'HR_HK_DIFF_BT_2_DATES'

exporting

date1 = '19950630'

date2 = '19950101'

IMPORTING

YEARS = w_year

months = w_mon

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.

Regards,

Pramod

0 Kudos

I don't think a program is needed for this. It is clear as daylight that the answer is 6 months.

0 Kudos

6 months: the time it will take to have OP understand all answers?

/sigh

0 Kudos

i want only month

matt
Active Contributor
0 Kudos

Well, the answer must be "one month" then.

0 Kudos

we should take this thread to CC..?

Former Member
0 Kudos

I prefer to have a multiple calendar table layout and perform a simple recursive searches and calculations from there..

One for each of: Julian, Gregorian, Mixed-Style Date, Dominical Letter suffix, a separate Holiday calendar table for each country and religion. and of course, let's not forget integrating in with the active Factory calenders in your SAP-instance.

I can send all the code, but I'll need an external address that can handle file attachments larger then 2.5gig.

0 Kudos

>

> I prefer to have a multiple calendar table layout and perform a simple recursive searches and calculations from there..

> One for each of: Julian, Gregorian, Mixed-Style Date, Dominical Letter suffix, a separate Holiday calendar table for each country and religion. and of course, let's not forget integrating in with the active Factory calenders in your SAP-instance.

>

> I can send all the code, but I'll need an external address that can handle file attachments larger then 2.5gig.

My FTP server can handle that! I'll set up an accoutn but only if you include the Mayan calendar as well.

Former Member
0 Kudos

Thanx Buddies