Q

Comparing dates

I am new to DB2, and I want to compare two dates, i.e., posted date with the expiry date. If posted date is more than seven days old, I need to archive that topic. Or if the current date is greater than expiry date, I need to archive that topic. How can I do the date comparisons in DB2? Is there any DB2-specific function for date comparisons?

DB2 offers a wealth of functionality in terms of its date/time arithmetic support and date/time functions. I suggest...

you take a look at the "DB2 SQL Reference" manual available for download from IBM's Web site to read up on DB2's date/time support. To answer your specific question, though, the following query/predicate should return the rows where the posted date is greater than 7 days from the expiry date:

SELECT COL1, COL2, ... 
FROM   YOUR_TABLE 
WHERE (POSTED_DATE + 7 DAYS) > EXPIRY_DATE; 

This was last published in January 2003

Dig Deeper on IBM DB2 management

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

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

Please create a username to comment.

-ADS BY GOOGLE

SearchBusinessAnalytics

SearchAWS

SearchContentManagement

SearchOracle

SearchSAP

SearchSOA

SearchSQLServer

Close