[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Comparision of dates in DB2

Posted on 2014-07-14
1
Medium Priority
?
633 Views
Last Modified: 2014-08-18
I have a query which says

select
ACCNO,
INSERTEDDATE AS LOADDATE,
ENDDATE,
date(A.INSERTEDDATE) AS LOADDATE2,
DATE(B.ENDDATE) AS ENDDATE2
name,
number
from
A,B
WHERE
A.ACCNO = B.ACCNO AND
DATE() > (INSERTEDDATE)  + 5
 AND DATE() <  (A.ENDDATE2 -45)


I would like to what is the function to compare dates in DB2
0
Comment
Question by:d27m11y
1 Comment
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 40195429
The syntax is mostly the same but you need to include units on the addition and subtraction.   Oracle always does math in days, but DB2 requires you to specify the date/time units.

select
ACCNO,
INSERTEDDATE AS LOADDATE,
ENDDATE,
date(A.INSERTEDDATE) AS LOADDATE2,
DATE(B.ENDDATE) AS ENDDATE2
name,
number
from
A,B
WHERE
A.ACCNO = B.ACCNO AND
DATE() > (INSERTEDDATE  + 5 days)
 AND DATE() <  (A.ENDDATE2 -45 days)


I'm assuming you'll fill in values for DATE() in your real query.

if DATE() was intended to be the db2 equivalent of oracle's trunc(sysdate), try

CURRENT DATE  (yes, two words, no underscore)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to recover a database from a user managed backup
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses
Course of the Month20 days, 7 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question