Converting Date for reporting by Year/Month or Year/Q

  • This has got to be easy.. I just can not seem to find how to do .. used Google.

    Looking to take a date field (2012-02-16) and converting for two new columns on my SQL statemet. One that will show Year/Month (2012-02) and a second one that will show the Quarter (2012-1).

  • Try DATENAME function

  • The problem is that when you do :

    SELECT [Server]

    ,DATENAME (YEAR, [Net_Day]) + ' / ' + DATENAME(MONTH, [Net_Day]) as 'Net_Day'

    ,[Start_Time]

    ,[End_Time]

    ,[Job_Cnt]

    ,[Dur_Min]

    FROM [Server_Manager].[dbo].[zt_Sysjob_Day_Sum]

    Then Pivot on Server (left) and Net_Day you get April, Febuary, March, May...

    Thus I need to get 2012/02, 2012/03, 2012/04.. ect

  • dwilliscp (5/4/2012)


    Thus I need to get 2012/02, 2012/03, 2012/04.. ect

    How about...

    select cast(datepart(Year,[Net_Day]) as varchar) + '/' + right('0' + cast(datepart(Month,[Net_Day]) as varchar),2) as [Year/Month],

    cast(datepart(Year,[Net_Day]) as varchar) + '/' + cast(datepart(Quarter,[Net_Day]) as varchar) as [Year/Quarter]

    FROM [Server_Manager].[dbo].[zt_Sysjob_Day_Sum]

    Rob Schripsema
    Propack, Inc.

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

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