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: 

Standard function to calcul dates ?

Former Member
0 Kudos
119

Hi.

I need a function where you can input 2 dates and it returns the difference between them like that :

Days : ..

Months : ..

For exemple : 18.01.2006 & 19.02.2006 and it returns : 1 day and 12 months.

I already have a solution from my own <b>but</b> i will have to use a <u>standard</u> function instead of mine ... if something like that exists. ^^

Anybody have ever use something like that ?

Thanks for the help !!


FUNCTION zcalcul_ecart_date.
*"----------------------------------------------------------------------
*"*"Interface locale :
*"  IMPORTING
*"     REFERENCE(I_DATE_DEB) LIKE  SY-DATUM
*"     REFERENCE(I_DATE_FIN) LIKE  SY-DATUM
*"  EXPORTING
*"     REFERENCE(ENBJOURS) TYPE  I
*"     REFERENCE(ENBMOIS) TYPE  I
*"----------------------------------------------------------------------

  w_date_deb = i_date_deb.
  w_date_fin = i_date_fin.


  CLEAR w_date_suiv.
  CLEAR w_nb_mois.
  CLEAR w_nb_jrs_rest.

  IF w_date_deb+4(2) <> w_date_fin+4(2).
    w_date_suiv = w_date_deb.
    PERFORM ajout_mois CHANGING w_date_suiv.

    DO.
      IF w_date_suiv <= w_date_fin.
        w_nb_mois = w_nb_mois + 1.
        IF w_date_suiv = w_date_fin.
          EXIT.
        ENDIF.
        PERFORM ajout_mois CHANGING w_date_suiv.

      ELSE.
        EXIT.
      ENDIF.
    ENDDO.

    IF w_date_suiv+4(2) = w_date_fin+4(2).

      IF w_date_suiv+6(2) <> w_date_fin+6(2).

        PERFORM retrait_mois CHANGING w_date_suiv.

        PERFORM calcul_nb_jrs_mois USING w_date_suiv
        CHANGING w_nb_jrs_mois.

        IF w_nb_jrs_mois > w_date_suiv+6(2).
          w_nb_jrs_rest = w_nb_jrs_mois - w_date_suiv+6(2).
        ENDIF.

        w_nb_jrs_rest = w_nb_jrs_rest + w_date_fin+6(2).

      ENDIF.

    ELSE.

      w_nb_jrs_rest = w_date_fin+6(2) - w_date_suiv+6(2).

    ENDIF.

  ELSE.
    w_nb_jrs_rest = w_date_fin+6(2) - w_date_deb+6(2).
    w_nb_mois = 0.
  ENDIF.

  enbjours = w_nb_jrs_rest.
  enbmois = w_nb_mois.


ENDFUNCTION.

7 REPLIES 7

former_member181962
Active Contributor
0 Kudos
73

check one of the following

SD_DATETIME_DIFFERENCE

HR_HK_DIFF_BT_2_DATES

0 Kudos
73

hi,

try this..

<b>FIMA_DAYS_BETWEEN_TWO_DATES</b>

regards

vijay

0 Kudos
73

Hi,

check this FM FIMA_DAYS_AND_MONTHS_AND_YEARS

the same output with parameters..

 Import parameters               Value                                                                                
I_DATE_FROM                     10/10/2004                                     
 I_KEY_DAY_FROM                  00                                             
 I_DATE_TO                       10/10/2005                                     
 I_KEY_DAY_TO                    00                                             
 I_FLG_SEPARATE                                                                                
Export parameters               Value                                                                                
E_DAYS                          365                                            
 E_MONTHS                        12                                             
 E_YEARS                         1                                                                                

regards

vijay

Former Member
0 Kudos
73

Hi,

Use this FM - MONTHS_BETWEEN_TWO_DATES.

Thanks

former_member181962
Active Contributor
0 Kudos
73

Few more Fms

FIMA_DAYS_BETWEEN_TWO_DATES_2

DAYS_BETWEEN_TWO_DATES

COMPUTE_YEARS_BETWEEN_DATES

HR_99S_INTERVAL_BETWEEN_DATES Get days,weeks, months and years between dates

HR_99S_MONTHS_BETWEEN_DATES Get months between dates

Former Member
0 Kudos
73

It's always a bit dangerous trying to determine the number of days <b>and</b> months between two dates. For example, is the difference between 2006.03.31 and 2008.02.28 one month or one month and three days?

Rob

Former Member
0 Kudos
73

Hi,

Try these two function modules as per u r requirement...

SD_DATETIME_DIFFERENCE

RP_CALC_DATE_IN_INTERVAL

Regards,

Azaz Ali Shaik.