Format Date in SQL Server

Discussion in 'SQL Server' started by go4expert, Nov 8, 2004.

  1. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    9
    Trophy Points:
    0
    I want to format the date of SQL server in the select statement but could not get it done.

    What I want is something like TO_DATE, TO_CHAR in Oracle.
     
  2. Amit Ray

    Amit Ray New Member

    Joined:
    Jul 12, 2004
    Messages:
    75
    Likes Received:
    4
    Trophy Points:
    0
    Occupation:
    Software Developer
    Home Page:
    http://www.go4expert.com
  3. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    9
    Trophy Points:
    0
    Hey Amit I am looking for SQL Server stuff and not MySQL.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I guess he mis read the query

    Hey you can use the convert function in SQL Server to achieve what you want.

    Here is an example of how to use it.
    Code:
    SELECT convert(varchar,getdate()) FROM <tablename>
    will show the output of current date in varchar format.
    First parameter is the output data type wanted and second is the Field Name you want to format. Here I have used the current system date.

    Thanks
    Shabbir Bhimani
     
  5. Amit Ray

    Amit Ray New Member

    Joined:
    Jul 12, 2004
    Messages:
    75
    Likes Received:
    4
    Trophy Points:
    0
    Occupation:
    Software Developer
    Home Page:
    http://www.go4expert.com
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
  7. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    9
    Trophy Points:
    0
    Hey Guys. Thanks for all the help and convert really worked the way I wanted.
     
  8. darsh999

    darsh999 New Member

    Joined:
    Oct 13, 2007
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    I think we have a option of change/remove the date over there in server !
    Have u tried that ?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice