Skip to Content
0
Former Member
Jan 19, 2006 at 10:49 AM

Standard function to calcul dates ?

39 Views

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.