tags:

views:

181

answers:

3

I want to the find differnece between two timestamps using COBOL. my timestamp is 16 bytes and here is the ex. of one timestamp: 2010060314314826 Please provide the sample code

A: 

Most probably formatted as:

YYYY MM DD HH MM SS CC

MOVE the timestamps in two fields such as:

 01 field-to-load.
    03 year   pic(9999).
    03 month  pic(99).
    03 day    pic(99).
    03 hour   pic(99).
    03 min    pic(99).
    03 sec    pic(99).
    03 cents  pic(99).

and perform the date/time arithmetic with the levels 03.

If your timestamps are not display-type data, you may need to do a previous conversion. If you need more detail about it post the field definition for the timestamp field.

I hope not to be banned from SO for posting cobol code.

HTH.

Edit

Here you can find a HP COBOL program for calculating date differences. You only have to add the (hour, min, sec) logic, very easy.

belisarius
A: 

Unless your version of Cobol has date/time math, you have two choices:

1) convert the date stamp into number of seconds per year since some arbitrary past date (17-nov-1978 for example), do the same with the date/time you are comparing it to, do a simple subtraction between the two results, and then convert the resulting number of seconds back into a delta time difference, or

2) subtract each portion of the date/time separately, account for the number of days in each month, and leap years (if you want it to work for more than 4 years). this option gets really hairy and has a very high failure rate, so I don't recommend it.

Carrie Cobol
A: 

If you are working in an IBM mainframe environment with LE support, try looking up: CEESECS--Convert timestamp to seconds. Using this routine you can convert each of your timestamps to Lilian seconds, then subtract one from the other giving a result in seconds.

This same guide provides COBOL code to do exactly what you are looking for. About the only change you need to make in this example is to the format of the timestamp as follows:

MOVE "YYYYMMDDHHMISS99" TO Vstring-text of PICSTR.

You may convert the seconds count into the number of days, hours, minutes etc. using the CEESECI--Convert seconds to integers service. Again, specific COBOL examples are provided.

NealB