Application Development and Automation 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: 
Read only

Convert Time to Date

Former Member
0 Likes
2,949

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??

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,710

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??

19 REPLIES 19
Read only

Former Member
0 Likes
2,711

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

Read only

0 Likes
2,710

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.

Read only

0 Likes
2,710

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

Read only

0 Likes
2,710

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

Read only

0 Likes
2,710

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

Read only

bishwajit_das
Active Contributor
0 Likes
2,710

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.

Read only

0 Likes
2,710

i also need to know the remaining minutes and seconds.
not only days..will these FM give as "days,hours,minutes,seconds" ??

Read only

0 Likes
2,710

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.

Read only

0 Likes
2,710

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.

Read only

bishwajit_das
Active Contributor
0 Likes
2,710

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.

Read only

0 Likes
2,710

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.

Read only

0 Likes
2,710

you can declare like this.

data: days type p decimals 2.

Read only

0 Likes
2,710

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.

Read only

0 Likes
2,710

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

Read only

0 Likes
2,710

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!!!

Read only

0 Likes
2,710

Hi Imran,  Now that your question is answered, close this discussion.  Regards, Bishwajit.

Read only

Former Member
0 Likes
2,710

Hello Askar,

Refer following thread.It might help you

http://scn.sap.com/thread/1247966

Katrice

Read only

bishwajit_das
Active Contributor
0 Likes
2,710

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.

Read only

Former Member
0 Likes
2,710

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.