DATE FORMAT MMYYYY for current date RRS feed

  • Question

  • Hi please help I need to get the current month and year Only from todays date (getdate)

    DATE FORMAT In  MMYYYY for current date

    Thanks In Advance

    Sunday, December 16, 2012 1:51 PM


All replies

  • Here is one way:

    SELECT LEFT(CONVERT(varchar,getdate(),101),2)+RIGHT(CONVERT(varchar,getdate(),101),4);
    -- 122012

    Datetime article:


    Kalman Toth
    New Book: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2016

    • Edited by Kalman Toth Thursday, November 9, 2017 2:48 PM
    Sunday, December 16, 2012 2:06 PM
  • select cast(month(getdate()) as char(2))+cast(year(getdate())as char(4))

    Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/

    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Blog: Large scale of database and data cleansing
    Remote DBA Services: Improves MS SQL Database Performance

    • Marked as answer by KODI_KODI Sunday, December 16, 2012 4:06 PM
    Sunday, December 16, 2012 2:10 PM
  • Try



    Many Thanks & Best Regards, Hua Min

    Sunday, December 16, 2012 2:28 PM
  • Well, there are lot of ways to do this,

    declare @dateval datetime
    set @dateval='01 Jan 2013'
    select right ('00'+ltrim(str(datepart(month,@dateval))),2 )+convert(varchar,datepart(year,@dateval))

    Sunday, December 16, 2012 3:34 PM
  • In SQL 2012:

       select format(getdate(), 'MMyyyy')

    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
    • Proposed as answer by Juniormint10 Wednesday, March 6, 2019 7:28 PM
    Sunday, December 16, 2012 5:00 PM
  • Thanks! 

    You could also use 'Myyyy' or 'M/yyyy' or 'M-yyyy' or 'MM-yyyy' or 'MM/yyyy'.

    By far, the simplest solution.


    Wednesday, March 6, 2019 7:30 PM
  • I know this is an old post but don't forget that FORMAT has been tested to be an average of 43 times slower than just about anything you can do with CONVERT or other date/time functions.

    --Jeff Moden

    Saturday, March 28, 2020 6:56 AM
  • By far, it's also the slowest solution.  FORMAT is an average of 43 times slower than CONVERT or most other temporal methods.

    --Jeff Moden

    Saturday, March 28, 2020 6:57 AM
  • Here's my take on this old post...


    --Jeff Moden

    Saturday, March 28, 2020 6:58 AM