Loading ...

Date Format in SQL

 /5
0 (0votes)

I wanted the date format from SQL in this way January, 2008. After doing searching I finally found the way to do it. Here is the solution:

SELECT
    DATENAME(month, DateCreated) AS ByMonth,
     DATENAME(yyyy, DateCreated) AS ByYear,
     COUNT(*) AS TotalCount FROM Test where userId=@UserID
     GROUP BY
     DATENAME(mm, DateCreated),
     DATENAME(yyyy, DateCreated)
     ORDER BY ByYear DESC

The output will be in this way now
ByMonth    ByYear    TotalCount
March    2009    6
January    2007    4

Comments (no comments yet)

Top Posts