EasyCFM.COM ColdFusion Forums / MS SQL Server Related Issues / Extract MonthName and Year from DateTime Field

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Extract MonthName and Year from DateTime Field

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

cdbymike
12-14-2006 @ 9:10 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 97
Joined: Jul 2004

How can I pull the MonthNamd and the year from a datetime field and join the together..

SELECT
datename(month, datefield) as eventMonth,
datepart(year, datefield) as eventYear
FROM
table

eventMonth and eventYear should be one (groupDate)

My cfoutput is doing a group on the GroupDate.

See the following link: (http://romanapostolicchurch.ohiowatch.com/calendar.cfm)



raulriera
12-15-2006 @ 2:14 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 69
Joined: Aug 2005

SELECT
datename(month, datefield) + ' ' + datepart(year, datefield) as groupDate
FROM
table
ORDER BY groupDate


This should do the trick (but it will sort it string wise and not date wise)

weathermanfsu
12-19-2006 @ 12:14 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 183
Joined: Apr 2004

This is better...

SELECT
datename(month, datefield) + ' ' + datepart(year, datefield) as groupDate
FROM
table
ORDER BY datefield

Any field can be in the order by clause.  It does not have to be a field you have in the select clause.  This will place it in date order.


Website Designed and Developed by Pablo Varando.