Skip to content

Instantly share code, notes, and snippets.

@dantesco
Created November 11, 2013 17:17
Show Gist options
  • Save dantesco/7416788 to your computer and use it in GitHub Desktop.
Save dantesco/7416788 to your computer and use it in GitHub Desktop.
diferencia entre 2 fechas y sus horas
* Variables necesarias para la función
DATA v_delta_time LIKE mcwmit-be_ae.
DATA v_delta_unit LIKE mcwmit-lzeit.
* Obtén la diferencia entre 2 fechas y 2 horas
CALL FUNCTION 'L_MC_TIME_DIFFERENCE'
EXPORTING
date_from = '20130716' "16.07.2013
date_to = '20130717' "17.07.2013
time_from = '233000' "11:30:00 pm
time_to = '103000' "10:30:00 am " diferencia 11 horas
IMPORTING
delta_time = v_delta_time " regresa 640
delta_unit = v_delta_unit " regresa min
EXCEPTIONS
from_greater_to = 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.
* Si el tiempo lo regresa en minutos
IF v_delta_unit = 'MIN'.
DATA: v_horas TYPE char10.
* Convierte los minutos en horas
CALL FUNCTION 'CONVERSION_EXIT_SDURA_OUTPUT'
EXPORTING
input = v_delta_time
IMPORTING
output = v_horas.
ENDIF.
WRITE: / 'tiempo ' , v_delta_time ,
/ 'unit ' , v_delta_unit .
WRITE: / 'tiempo convertido en horas', v_horas.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment