Home > Ask the Data Management Experts > Questions & Answers > DB2 date conversion
Ask The Data Management Expert: Questions & Answers
EMAIL THIS

DB2 date conversion

Craig Mullins, Years 2005-2006 EXPERT RESPONSE FROM: Craig Mullins, Years 2005-2006

Pose a Question
Other Data Management Categories
Meet all Data Management Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 13 May 2003
In my database date is stored in numeric format yymmdd i.e. for MAY 13, 2003 it is stored as 30513. I want to compare this date between two dates, one is the current date and the other is 1 year from current date. I can get the current date from sysibm.sysdummy1 but the format is 2003-05-13 which is not numeric. So my question is how can I convert the date to numeric format and compare my database date between the converted dates? Thanking you and waiting for your reply.

>
EXPERT RESPONSE

Well, you will need to use CURRENT DATE along with some DB2 functions and some additional logic. First of all, the following functions will return the day, month, and year component of a date:
DAY(CURRENT DATE)
MONTH(CURRENT DATE)
YEAR(CURRENT DATE)

So, for today, the first would return 12, the second 5, and the last 2003. To get that into your format you would have to do something like this:

YOUR_FORMAT_DATE = ((YEAR(CURRENT DATE) - 2000) * 10000) +
                    (MONTH(CURRENT DATE) * 100) +
                     DAY(CURRENT DATE)

That should return the date in the numeric format you want (at least until the year 2100). But you'd be much better off using DB2 dates in your tables!


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
IBM DB2
IBM DB2 9 Fundamentals certification (Exam 730): Sample questions about tables, Part 6
IBM DB2 9 Fundamentals certification (Exam 730): Sample questions about tables, Part 5
DB2 basics
IBM DB2 basics
IBM DB2 9 Fundamentals certification (Exam 730): Sample questions about tables, Part 4
DB2 looks to enterprise information management to fend off Microsoft
DB2 tools and products for Linux, UNIX and Windows: The basics
Understanding IBM DB2: Product history and strategy
IBM DB2 9 Fundamentals certification (Exam 730): Sample questions about tables, Part 3
IBM DB2 9 Fundamentals certification (Exam 730): Sample questions about tables, Part 2

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2005 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts