Home Forums SQL Server 2008 T-SQL (SS2K8) How To return Year & Month in this format: 2013-06 RE: How To return Year & Month in this format: 2013-06

  • Teee (6/19/2013)


    Hi All,

    I need to return the minimum date from my table and manipulate it so it starts from the first of the month

    e.g 2012-06+'-'+'01+ and use this as the minimum date: '2012-06-01- instead of the 22nd

    Select MIN(dtePostedToWebsiteDate) --Here's the minimum date >>> 2012-06-22 09:07:42.413

    FROM dtlVacancyPostAudit

    How do I achieve this?

    Thanks

    Teee

    Select DATEADD(MONTH, DATEDIFF(MONTH, 0, MIN(dtePostedToWebsiteDate)), 0)

    FROM dtlVacancyPostAudit;

    Or

    Select CAST(DATEADD(MONTH, DATEDIFF(MONTH, 0, MIN(dtePostedToWebsiteDate)), 0) AS DATE)

    FROM dtlVacancyPostAudit;


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/