Display only month and year as MM/YYYY

  • Hi

    I found this to convert at date

    cast(cast(sq.QuotaDate as date) as varchar(7))

    and it works by giving me 2014-02 for 02/07/2014

    I would like it to read 02/2014

    Not sure how to change?

    Thanks

    Joe

  • You want to use CONVERT with a format code. (Reference)

    Can you handle that? or you need more help?

    Remember that this information is available with F1 on SSMS.

    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
  • A CONVERT to format 101 will give us format "mm/dd/yyyy". Then, using STUFF, we can remove the "dd/", leaving you with what you want:

    SELECT STUFF(CONVERT(varchar(10), GETDATE(), 101), 4, 3, '')

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Or you could use code 103 with a RIGHT or SUBSTRING.

    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

Viewing 4 posts - 1 through 3 (of 3 total)

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