How to retrieve a DB2 date in Julian format

How to retrieve a DB2 date in Julian format

How do I get the DB2 date from a table in Julian format? I did write a query concatenating year and days, but it wasn't useful. It gave the SQL error -171. Please help.

    Requires Free Membership to View

    By submitting your registration information to SearchOracle.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchOracle.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

SQL error -171 means "The SQL statement includes an unknown scalar function." Without seeing your query, I cannot tell what you did wrong. But never mind. I think the following will do it:

select year(thedate)
     , dayofyear(thedate)
  from yourtable

YEAR() and DAYOFYEAR() are DB2 scalar functions which return integers for the year and day of year (1-366), respectively. The day of year between 1 and 366 is what most people mean when they use the term "Julian."

If, instead of integers, you wanted a YYYYDDD string, you could use the CAST function:

select cast( year(thedate) * 1000
             + dayofyear(thedate) as char(7) )
  from yourtable

For More Information


This was first published in January 2003

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.