change DATE format to DD/MMM/YYYY

  • I have created a table with a field Register_Date in DATE format. However, it results showed me 21/12/2008

    I would like to change it to 21/Dec/2008

    How do I change that using SQL command? I tried to Google and used codes like below and it will not work

    SELECT CONVERT( CHAR(6), Register_Date, 106 )

    FROM REG

    The error message was ORA-00936: missing expression

    I also tried:

    SELECT replace(convert(char(15),Register_Date,106),' ',' - ')

    FROM REG

    and it gives it the same error message.

    Any suggestions?

    Thanks

  • Here's one way. Not sure if there's anything more elegant.

    declare @d date = '20081221'

    select @d

    ,replace(convert(char(11), @d, 13), ' ', '/')

    And presumably you are aware that formatting of dates for display purposes is usually something which is done by the client application.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Thank you so much. However, the declare function is giving me an error message

    ORA-06550: line 1, column 9:

    PLS-00103: Encountered the symbol "@" when expecting one of the following:

    begin function pragma procedure subtype type <an identifier>

    <a double-quoted delimited-identifier> current cursor delete

    exists prior

    1. declare @d date = '20081221'

    I may have done something wrong since I am new to SQL

  • sk88 (2/22/2015)


    Thank you so much. However, the declare function is giving me an error message

    ORA-06550: line 1, column 9:

    PLS-00103: Encountered the symbol "@" when expecting one of the following:

    begin function pragma procedure subtype type <an identifier>

    <a double-quoted delimited-identifier> current cursor delete

    exists prior

    1. declare @d date = '20081221'

    I may have done something wrong since I am new to SQL

    Are you using Oracle?

    😎

  • Yes you are right. I am using Oracle

  • sk88 (2/22/2015)


    Yes you are right. I am using Oracle

    You're in the wrong forum, I'm afraid: this one is for SQL Server 🙂

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • I thought its related to SQL so I came here 😀 hahah sorry. I will post in the Oracle forum.

    Thanksss!!

  • sk88 (2/22/2015)


    I thought its related to SQL so I came here 😀 hahah sorry. I will post in the Oracle forum.

    Thanksss!!

    That would be fine, if all dialects of SQL were the same. But, as you've discovered, they are often quite different, once you go beyond SELECT, INSERT, UPDATE and DELETE.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • This is simple and any Oracle forum should give you the answer, but I'll include it here.

    You need to use the TO_CHAR() function to format dates and TO_DATE() to enter dates in a specific format.

    eg.

    SELECT TO_CHAR(SYSDATE, 'DD/MON/YYYY')

    ,TO_DATE('21/FEB/2015', 'DD/MON/YYYY')

    FROM Dual;

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares (2/23/2015)


    This is simple and any Oracle forum should give you the answer, but I'll include it here.

    You need to use the TO_CHAR() function to format dates and TO_DATE() to enter dates in a specific format.

    eg.

    SELECT TO_CHAR(SYSDATE, 'DD/MON/YYYY')

    ,TO_DATE('21/FEB/2015', 'DD/MON/YYYY')

    FROM Dual;

    Traitor! :hehe:

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Phil Parkin (2/23/2015)


    Luis Cazares (2/23/2015)


    This is simple and any Oracle forum should give you the answer, but I'll include it here.

    You need to use the TO_CHAR() function to format dates and TO_DATE() to enter dates in a specific format.

    eg.

    SELECT TO_CHAR(SYSDATE, 'DD/MON/YYYY')

    ,TO_DATE('21/FEB/2015', 'DD/MON/YYYY')

    FROM Dual;

    Traitor! :hehe:

    I'm just demonstrating that SQL Server community is more helpful than many others. 😀

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Phil Parkin (2/23/2015)


    Luis Cazares (2/23/2015)


    This is simple and any Oracle forum should give you the answer, but I'll include it here...

    Traitor! :hehe:

    Nah, he's just bi-something. 😀

    -----
    [font="Arial"]Knowledge is of two kinds. We know a subject ourselves or we know where we can find information upon it. --Samuel Johnson[/font]

  • can you try this.

    select replace(CONVERT(VARCHAR(11),GETDATE(),106),' ','/')

  • select replace(CONVERT(VARCHAR(11),GETDATE(),106),' ','/')

  • gopi6417 (2/25/2015)


    select replace(CONVERT(VARCHAR(11),GETDATE(),106),' ','/')

    Does this syntax work on Oracle?

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic. Login to reply