09-11-2008 6:31 PM
I want to convert decimals hours into hh:mm:ss
i.e. 1.38 into 1:22:48
please give me any function module or
is there any formula
09-11-2008 7:32 PM
in simplerway you can do this..
REPORT ztest_time_conv.
DATA: hour(2) TYPE n,
min(2) TYPE n,
sec(2) TYPE n,
tim TYPE i.
DATA: time TYPE p DECIMALS 2.
DATA: timeformat TYPE sy-uzeit.
time = '1.38'.
tim = time * 3600.
hour = tim DIV 3600.
tim = tim MOD 3600.
min = tim DIV 60.
sec = tim MOD 60.
CONCATENATE hour min sec INTO timeformat.
WRITE timeformat.
BREAK-POINT.
09-11-2008 7:19 PM
Hi,
Please try this code..
DATA: v_value TYPE p DECIMALS 2.
DATA: v_string TYPE string.
DATA: v_int TYPE numc2.
DATA: v_time TYPE syuzeit.
v_value = '1.38'.
IF v_value > '24.00' OR v_value < 0.
MESSAGE s208(00) WITH 'Not possible'.
EXIT.
ENDIF.
* Move the value to a string.
v_string = v_value.
* Hour.
SPLIT v_string AT '.' INTO v_time(2) v_int.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = v_time(2)
IMPORTING
output = v_time(2).
* Minute
v_value = 60 * v_int / 100.
v_string = v_value.
SPLIT v_string AT '.' INTO v_time+2(2) v_int.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = v_time+2(2)
IMPORTING
output = v_time+2(2).
* Second
v_value = 60 * v_int / 100.
v_string = v_value.
SPLIT v_string AT '.' INTO v_time+4(2) v_int.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = v_time+4(2)
IMPORTING
output = v_time+4(2).
WRITE: / v_time.
Thanks
Naren
09-11-2008 7:32 PM
in simplerway you can do this..
REPORT ztest_time_conv.
DATA: hour(2) TYPE n,
min(2) TYPE n,
sec(2) TYPE n,
tim TYPE i.
DATA: time TYPE p DECIMALS 2.
DATA: timeformat TYPE sy-uzeit.
time = '1.38'.
tim = time * 3600.
hour = tim DIV 3600.
tim = tim MOD 3600.
min = tim DIV 60.
sec = tim MOD 60.
CONCATENATE hour min sec INTO timeformat.
WRITE timeformat.
BREAK-POINT.
08-25-2010 6:02 PM
Hi all
The example mentioned here leads to 0:19 Minutes in case of input of 0,33. I want to have it 0:20 Minutes (1/3 Hour). Therefore, I elaborated the following code:
*** Format hours minutes from a decimal representation which is passed in a text string
* e. g. 0,33 --> 0:20
DATA: tim TYPE p DECIMALS 2,
hour TYPE n,
min_p TYPE p,
min(2) TYPE n
e_time type char5,
i_time type char 5.
REPLACE ',' IN i_time WITH '.'.
tim = i_time.
min_p = 60 / ( 100 / i_time ) * 100.
min = min_p MOD 60.
hour = min_p / 60.
IF min = 59. " result 59 happens if we get 0,99 which is equal to one hour regarding the rounding difference
min = '00'.
ENDIF.
if min > 29. " in this case the hour calculation returns one hour too much due to rounding above
hour = hour - 1.
endif.
WRITE min TO min ROUND 1 DECIMALS 0.
CONCATENATE hour ':' min INTO e_time.
Edited by: Philippe Addor on Aug 26, 2010 1:50 PM
Edited by: Philippe Addor on Aug 26, 2010 1:52 PM
09-11-2008 7:37 PM
Hi Vijay,
Good one. I forgot about the MOD function ..
Regards
Naren
09-11-2008 7:37 PM
Duplicate..
Edited by: Narendran Muthukumaran on Sep 11, 2008 8:37 PM