2013 Feb 25 7:23 AM
Hi experts..
I am having a requirement to convert TIME into DATE.
i have TEN FIELDS of TIME for the user to enter,when he enters time in all the 10 fields,i need to calculate the total time and days.
let me tell if the user has entered time as,
1-> 10:43
2-> 21:00
3-> 3:00
4-> 5:00
the total time is 1 day,15 hours,43 mintues.
Is there any function module??
2013 Feb 25 7:38 AM
Hi Askar
You can do it like :
add the total time in terms of hours and store it in a varaible .
like
a = 39 . ************ hours
b = 43. **************** minutes
and further
c = a / 24. * here c will have a value : 1.625 days
split c at '.' into var1 var2.
var1 has 1 which is the number of days .
var2 = .625 * 24. * it is number of hours
so you have days in var1 , hours in var2 and minutes in b.
regards
vaibhav
Hi experts..
I am having a requirement to convert TIME into DATE.
i have TEN FIELDS of TIME for the user to enter,when he enters time in all the 10 fields,i need to calculate the total time and days.
let me tell if the user has entered time as,
1-> 10:43
2-> 21:00
3-> 3:00
4-> 5:00
the total time is 1 day,15 hours,43 mintues.
Is there any function module??
2013 Feb 25 7:38 AM
Hi Askar
You can do it like :
add the total time in terms of hours and store it in a varaible .
like
a = 39 . ************ hours
b = 43. **************** minutes
and further
c = a / 24. * here c will have a value : 1.625 days
split c at '.' into var1 var2.
var1 has 1 which is the number of days .
var2 = .625 * 24. * it is number of hours
so you have days in var1 , hours in var2 and minutes in b.
regards
vaibhav
2013 Feb 25 7:44 AM
Thanks a lot for your reply...
since am a beginner,am having few doubts.
when i add the total time it adds and gives in 'SECONDS'.
i have 'TIMS' for all the fields the user enters.
when i sum up them it gives the total in seconds.
2013 Feb 25 8:21 AM
Hi
do one thing
you have total time in seconds , right ?
so lets say a variable a has this value
then try :
b = a / 3600. *******this will give the value in hours , b should be floating type to have decimal values
for ex b = 3.652
now break b
split b at '.' into var1 var2.
var1 will have hours only
for hours calcualtion further : do further as above reply .
var2 = var2 * 60.*******this will give var2 in terms of minutes which is again in decimal.
var2 has value 39.12
and you can add the var2 and minutes obtained from above calculation for total minutes.
I hope its clear.
close the thread if issue is resolved .
reward points if helpful/correct
regards
vaibhav
2013 Feb 25 11:23 AM
Thanks a lot for your reply..
Actually i cant split up two values.
when dividing it,the value doesn't come as floated,its truncated value.
when i use split it allows to define data type only of (c,n,d,t).
what type of data type should i use??
because its truncating the values and giving it to var1 and var2.
so var2 will always be '0'.
Message was edited by: Askar Imran
2013 Feb 26 4:05 AM
hi
to have decimal value instead of using split you can use offset , what you can do is
ex:
move var1+0(2) to var2.
this will move first two characters of var1 to var2.
move var1+2(5) to varr3.
this will move the second half value with decimal in var3.
regards
vaibhav
2013 Feb 25 8:04 AM
Hi Imran,
You can try these Function Modules :-
'RSSM_CONVERT_TIMESTAMP2DAYSEC'
or
'ADDR_CONVERT_TIMESTAMP_TO_DATE'...
to convert the total time in seconds to DAYS
Wish this will suffice your problem..
Regards,
Bishwajit.
2013 Feb 25 8:08 AM
i also need to know the remaining minutes and seconds.
not only days..will these FM give as "days,hours,minutes,seconds" ??
2013 Feb 25 8:14 AM
hi,
hrs_tmp = 0
min_tmp = 0
days = 0
hrs = 0
min = 0
a = 10:43
b = 21:00
if a is not initial.
split a at ':' into hrs_tmp min_tmp.
perform add using hrs_tmp min_tmp.
clear: hrs_tmp min_tmp.
endif.
if b is not initial.
split b at ':' into hrs_tmp min_tmp.
perform add using hrs_tmp min_tmp.
clear: hrs_tmp min_tmp.
endif.
perform calculate.
form add using hrs_tmp min_tmp.
hrs = hrs + hrs_tmp.
min = min + min_tmp.
endform.
form calculate.
min = min/60.
split min at '.' into hrs_tmp min.
hrs = hrs/24.
split hrs at '.' into days hrs.
hrs = hrs + hrs_tmp.
endfom.
2013 Feb 25 8:19 AM
Hi Imran ,
There is no standard FM ,the way you want the output.
In that case you have to convert the remaining time in seconds to hours:minutes:seconds by creating your own logic.
Regards,
Bishwajit.
2013 Feb 25 8:45 AM
Hi Imran,
You can do one thing.Study the solution properly...I wish you will get your result
Store the total seconds in a variable ' tot_sec'.
Let, number of days = days
number of hours = hrs
number of minutes = mins
number of seconds = sec
*MOD can be a useful operator.
* 86400 comes from 24x60x60.
days = tot_sec / 86400.
*Now remaining seconds
tot_sec = tot_sec MOD 86400 .
* 3600 comes from 60x60.
hrs = tot_sec / 3600.
*Now remaining seconds
tot_sec = tot_sec MOD 3600.
mins = tot_sec / 60.
*Now remaining seconds
tot_sec = tot_sec MOD 60.
sec = tot_sec.
Regards,
Bishwajit.
2013 Feb 25 11:18 AM
Thanks a lot for your reply..
i tried this...
but when the value for days = 1.99,it rounds it off to 2.
it takes it as 2 days.
actually my input time was,
24:00,
23:55,
Think this seems to be an error.
2013 Feb 25 12:27 PM
2013 Feb 26 6:35 AM
Could you please help in this ?
now i have this 3 fields,->hours,minutes,seconds i need to save this on data base table in 'TIMS' format.
how is it possible?
please help.
2013 Feb 26 6:51 AM
Hi Imran, To convert the 3 fields(hrs,mins & secs) into one fields of TIMS format, try this:- DATA: time TYPE TIMS, hh TYPE n, mm TYPE n, ss TYPE n. time = (hh * 10000) + (mm * 100) + (ss * 1). Wish this will solve your purpose. Regards, Bishwajit
2013 Feb 26 7:31 AM
Thanks for your reply.
but i made it simple.
i just CONCATENATE'd the values.
CONCATENATE hours minutes seconds to time.
did this way,and its working!!!
2013 Feb 26 7:35 AM
Hi Imran, Now that your question is answered, close this discussion. Regards, Bishwajit.
2013 Feb 25 8:56 AM
2013 Feb 25 11:31 AM
Hi Imran,
Try simple way to solve the problem..
Remainder = Dividend MOD Divisor.
Dividend = Dividend - Remaider.
Quotient = Dividend / Divisor.
Then you will get exact values (like number of days) avoiding any rounding off.
Regards,
Bishwajit.
2013 Feb 25 1:56 PM
try this.
data: l_time1 type syuzeit,
l_time2 type syuzeit,
l_time3 type syuzeit,
l_time4 type syuzeit,
l_total type syuzeit,
l_tot_days type i,
l_tot_hrs type i,
l_tot_min type i,
l_tot_sec type i,
l_min type i,
l_hrs type i,
l_days type i.
l_time1 = '134405'.
l_time2 = '230101'.
l_time3 = '051212'.
l_time4 = '121244'.
l_tot_hrs = l_time1(2) + l_time2(2) + l_time3(2) + l_time4(2).
l_tot_min = l_time1+2(2) + l_time2+2(2) + l_time3+2(2) + l_time4+2(2).
l_tot_sec = l_time1+4(2) + l_time2+4(2) + l_time3+4(2) + l_time4+4(2).
write:/ l_time1,
/ l_time2,
/ l_time3,
/ l_time4.
skip 1.
write: /'Total hours :', l_tot_hrs,
/'Total minutes:', l_tot_min,
/'Total seconds:', l_tot_sec.
skip 1.
* how many minutes in total seconds?
l_min = l_tot_sec div 60.
* up the total minutes
l_tot_min = l_tot_min + l_min.
* remaining seconds
l_tot_sec = l_tot_sec mod 60.
* How many hours in total minutes?
l_hrs = l_tot_min div 60.
* up the total hours
l_tot_hrs = l_tot_hrs + l_hrs.
* reminaing minutes
l_tot_min = l_tot_min mod 60.
* How many days in total hours?
l_days = l_tot_hrs div 24.
* up the total days
l_tot_days = l_tot_days + l_days.
* remaining hours
l_tot_hrs = l_tot_hrs mod 24.
write: / 'Days :', l_tot_days,
/ 'Hours :', l_tot_hrs,
/ 'Minutes :', l_tot_min,
/ 'Seconds :', l_tot_sec.