November 19, 2009 at 10:49 am
I need to show record counts counts for each month of the year... January 160 records, February, 900 records based on records which contain a datetime field containing short date data (example 4/17/2006)
Is there a method to convert the exact date to just show the Month the date occured in for the purposes of the counting I need to do?
The format of the date field is datetime 8 characters
Thanks!
November 19, 2009 at 10:53 am
you can use MONTH
SELECT MONTH(GETDATE())
or for the Month name
SELECT DATENAME(MM,GETDATE())
November 19, 2009 at 11:04 am
If the field name in this case is "referdate", where does it go with your code?
referdate (MM,GETDATE()) ?
my example of course which did not work.. thus my question..
Thanks..
November 19, 2009 at 11:59 am
Is the data restricted to a 12 month period or is there more than one year?
Also, referdate would go in place of getdate().
November 23, 2009 at 8:38 am
The data spans two calendar years (one school year)...
September one year to June the next year
November 23, 2009 at 8:41 am
If my data changes calendar year (which it does, as I'm measuring data throughout a school year... September one year to June of the next year) will need to show the month number and the year in the returned data. Are there similar formatting codes to show just the current year (09, or 2009), or just the month number (01 January, 04 April), etc?
November 23, 2009 at 8:52 am
Three are formats to strip out any part of the date by using DATEPART
for the year you would use
SELECT DATEPART(yy,GETDATE())
to build your own custom date formats you can use the multiple functions
SELECT DATEPART(day, GETDATE()),datename(month, GETDATE()), DATEPART(year, GETDATE())
A lot more info here
http://msdn.microsoft.com/en-us/library/ms174420.aspx"> http://msdn.microsoft.com/en-us/library/ms174420.aspx
November 23, 2009 at 9:04 am
There is this function, YEAR().
SELECT YEAR(GETDATE())
November 23, 2009 at 10:47 am
Thanks for the fishing lesson and rod!
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply