Date/Time group

  • 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!

  • you can use MONTH

    SELECT MONTH(GETDATE())

    or for the Month name

    SELECT DATENAME(MM,GETDATE())

  • 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..

  • Is the data restricted to a 12 month period or is there more than one year?

    Also, referdate would go in place of getdate().

  • The data spans two calendar years (one school year)...

    September one year to June the next year

  • 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?

  • 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

  • There is this function, YEAR().

    SELECT YEAR(GETDATE())

  • 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