How do I use DateDiff in cobol using SELECT statement?

35 pts.
Tags:
AS/400
COBOL
DATEDIFF
SELECT statement
how to use DateDiff in cobol using SELECT satement.

Software/Hardware used:
as/400

Answer Wiki

Thanks. We'll let you know when a new response is added.

First question I have is what release of the OS are you on? COBOL has intrinsic functions to do this very easy. This is an example of this function:

<pre>
01 TIME-DIFF PIC S9(09) VALUE ZEROES.
01 START-TIME FORMAT TIMESTAMP VALUE ’2000-01-01-00.00.00.000000′.
01 END-TIME FORMAT TIMESTAMP VALUE ’2000-01-01-00.00.00.000000′.

COMPUTE TIME-DIFF =
FUNCTION FIND-DURATION (START-TIME END-TIME SECONDS).

</pre>

The ILE reference manual will show the options in the FIND-DURATION function.

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    Since neither COBOL nor SQL has a DateDiff function, please explain what you need to accomplish. Do you need to calculate a date duration in COBOL? Do you need to calculate a date duration in SQL? Are you displaying or reporting the duration? Are you updating a file with a duration? What version of i5/OS are you running under? Tom
    125,585 pointsBadges:
    report
  • Ije
    Yes I want to calculate the time duration in cobol. Well there is "DateDIff" in sql and I am trying to use in embedded sql in Cobol ille. And the ver is 5.8
    35 pointsBadges:
    report
  • carlosdl
    The DateDiff function returns the difference between two dates, and it is present in some SQL implementations (MS SQL Server, Sybase, MS Access) but I guess it is not standard SQL. Some other database systems let you perform arithmetic operations between dates to achieve similar results (Oracle, and possibly DB2).
    68,710 pointsBadges:
    report
  • TomLiotta
    ...there is “DateDIff” in sql ... As Carlosdl noted, DateDiff is not part of SQL. A major confusion among new SQL developers, or SQL developers who have learned limited implementations, comes from proprietary extensions that are provided by different vendors. They tend to assume that what they have learned is "SQL" and anything else is somehow wrong. DATEDIFF is an example of a proprietary function that is provided by some vendors as an extension. It is outside of SQL, but may used in some SQL statements on some platforms. Even among platforms that do provide it, the implementations may be incompatible or give different results. Some function differences come from lower level differences in underlying data types. MS SQL and MySQL have a DATEDIFF function while not fully supporting some SQL data types for date, time or timestamp; but they have a DATETIME data type that is slightly different between them and slightly different from how SQL specifies the data types should be handled. Oracle, OTOH, implements the SQL standard very closely but doesn't have DATEDIFF. DB2 doesn't support the allowed SQL extension of TIMESTAMP WITH LOCAL TIME ZONE, but otherwise supports the related SQL data types well and also doesn't have DATEDIFF. In short, SQL itself doesn't have DATEDIFF in the standard. You can't rely on specific extensions when working in a new, unfamiliar implementation. The point is that it is the operation that is important. So, what do you need to accomplish? Do you have two dates and you need to calculate the number of days between them? Or instead of dates, do you have two timestamps and need the interval in days? Or do you need the interval in months? Years? Is this simply a COBOL calculation or do you need a SQL calculation? If you have a COBOL program that is using embedded SQL to process database transactions, you might want a SQL solution. But maybe you can simply do it natively in COBOL if SQL isn't already being used for other purposes in the program. You wanted to use DATEDIFF. What exactly were you going to use it for? There are COBOL functions that are similar and there are SQL functions that are similar. The right choice depends on what you need to accomplish. Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following