Skip to Content
author's profile photo Former Member
Former Member

how to get year out of a date database field

Hi,

I got a Oracle database field "createddate', i want get year from this field.

i Tried: to_date(to_char(createddate,'yyyy'),'yyyy')

i laso tried: trunc(createddate,'yyyy')

also tried: to_date(substr(to_chart(createddate),7,11,)'yyyy')

but when i test in Webi, i got '1/1/11' what's the right syntext?

Thanks

Edited by: hiccup on Dec 8, 2011 6:55 PM

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 09, 2011 at 08:04 PM

    You don't need to to_date() the result, as a year is not a date but either a numeric 2011 or character '2011' value. To extract the year from any date use

    to_char(createdate,'YYYY')

    only. If you want the result to be numeric, then use to_number() after you have extracted the year using the to_char() function.

    Object formats only change the way something looks, they don't change the actual value, and should not be used for this.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 09, 2011 at 02:29 AM

    I think Universe has Year() function that can be used.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 09, 2011 at 04:49 PM

    hi,

    one more thing if you right click on the universe object and apply format in the format object.

    Thanks,

    Amit

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi, Amit,

      Actually I used the "object format", I added "yyyy" as a new "format" on my computer, then the Universe works perfect for the Webi report on my computer.

      But after I export this Universe to the repository, when other developers used same universe, the Webi report just

      didn't turn out nice.

      What do i have to do? How to keep this new format coming cross?

      Add "yyyy" to the server and modify each developer's computer? doesn't sound right.

      Thanks

  • author's profile photo Former Member
    Former Member
    Posted on Dec 12, 2011 at 02:38 PM

    apply automatic hierarchy in the properties of your date object and it will create a year object

    Edited by: PadawanGirl on Dec 12, 2011 3:38 PM

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.