Date Format in SQL Statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mikewin86
    New Member
    • Mar 2010
    • 17

    Date Format in SQL Statement

    Hello,


    I would like to ask a question.

    How can I format the Date Value in SQL Statement like this?

    SELECT Format(OrderDat e,"MMM-yyyy") etc


    In vb.net we can format Date Value like this.

    Format(OrderDat e,"MMM-yyyy")

    Thanks in advance

    Mike
  • Jerry Winston
    Recognized Expert New Member
    • Jun 2008
    • 145

    #2
    Try this:

    MSDN

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      It's always recommended to do the formatting in the front-end, not the back end...

      Good Luck!!!

      ~~ CK

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32636

        #4
        That particular format is not supported by CONVERT(). You will probably need to use something like :
        Code:
        SELECT CONVERT(nvarchar(3), [OrderDate], 109) + '-' + CAST(YEAR([OrderDate])) AS nvarchar(4)) AS [YourFieldName]
        As CK says though, in most circumstances this is better done by the client than the SQL Server (IE. Don't do it in the SQL at all).

        Comment

        • mikewin86
          New Member
          • Mar 2010
          • 17

          #5
          Thanks NeoPa.

          It work well with my query.

          Thanks all for your suggestions.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32636

            #6
            That's fine Mike. Glad to help. I guess you went for the SQL version in the end then. Only you can know your full requirements. We can only advise.

            Comment

            Working...