Month Function of MSSQL DateTime field

We can get the month part in number 1 to 12 by using Month function in MSSQL. Here is the query to get Month part along with the full date.

select Month(issue_dt) as month, issue_dt from dt

The output of this query is here.
12 12/28/2007 7:54:56 PM
10 10/31/2010 7:23:47 PM
10 10/31/2010 7:30:14 PM
10 10/31/2010 7:30:20 PM
2 2/28/2010 7:54:56 PM
As you have seen we have shown month along with the full date, now we will try to list out number of issues in every month by using Group by command. We will display Total number along with the month number. Here is the query. " select COUNT(issue_dt) as no, Month(issue_dt) as isdt from dt GROUP BY Month(issue_dt)

Month isdt
2 1
10 3
12 1
The left column is the month and next column shows number of issues against that month. You can check from the first display list the numbers to the second display list

Be the first to post comment on this article :

Post your comments , suggestion , error , requirements etc here .

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2022 All rights reserved worldwide Privacy Policy Disclaimer