Page 1 of 1

Difference between time

PostPosted: Mon May 20, 2013 9:52 pm
by deva_048
Hi

My input file contains the date such as following format mentioned below

Start time 01:00
End Time 01:30

I have written a cobol program to moving these two times into two working storage variable in ready now. Now i have to calculate the difference between two times i.e) Endtime - start time to store in new variable and to add 3 hours in start time to display elapsed time as 4:00 to store in new variable.

Can anyone give solution to implement this in cobol. Please suggest me the solution.

Thanks in advance

Re: Difference between time

PostPosted: Mon May 20, 2013 10:07 pm
by dick scherrer
Hello,

First you need to be sure the times are in the same 24-hour day. If not, then you need to include the dates.

One way is to:
. Convert both to seconds
. Subtract the start seconds from the end seconds (after ensuring the end is greater than the start) to get elapsed seconds
. Convert the elapsed seconds back to HH:MM:SS to show the results

Re: Difference between time

PostPosted: Mon May 20, 2013 10:10 pm
by deva_048
Thanks.I forgot to say that the times in format HH:MM:SS in input file for both start and endtime. Is compute function will work for to subtract these ??

Re: Difference between time

PostPosted: Mon May 20, 2013 10:26 pm
by dick scherrer
Hello,

No - You need to comvert the times to seconds or use something that can do arithmetic with formatted date/time values.

Re: Difference between time

PostPosted: Mon May 20, 2013 10:42 pm
by Robert Sample
Compute starting seconds as hours * 3600 + minutes * 60 + seconds. Compute ending seconds as hours * 3600 + minutes * 60 + seconds. The difference in seconds can be converted back to hours / minutes / seconds easily enough.

Things to consider:
1) will your data span a day boundary (start at 11 PM, end at 1 AM)?
2) is your data in 12-hour or 24-hour format?
3) can your data span more than one day? If so, how do you detect that?
4) is the data computer-generated, or human-generated? If the latter, do you need to think about one-digit versus 2-digit hours, minutes, seconds?
5) do you need to be concerned with daylight savings time? If so, how do you detect that?

That should start you thinking in the right direction.

Re: Difference between time

PostPosted: Mon May 20, 2013 10:48 pm
by Akatsukami
Deva-kun, I recommend that you investigate the Language Environment services CEESECS and CEEDATM for ways to handle many of Mr. Sample's points.