Skip to main content
Known Participant
November 13, 2008
Question

Need help sorting out dates

  • November 13, 2008
  • 4 replies
  • 483 views
Sorry for this question but I have not coded in few years.
I have a basic table with a date column and event name column and an ID column.
I want to output the events in order of years, then month

for example

2008
Janurary
01/05/2008 Tv show event
01/15/2008 another event
01/23/2008 trade event

Feburary
02/10/2008 anothe trade event
02/14/2008 another event

March
No events
......
..
..
..

2009
January
01/05/2009 Tv show event
01/15/2009 another event
01/23/2009 trade event

Any help on how to sort this information this way is much appreciated.
Thanks
This topic has been closed for replies.

4 replies

Known Participant
November 13, 2008
Thanks again, much appreciated.
Inspiring
November 13, 2008
andy99 wrote:
> Thanks Ian.
> This is what I wanted.
> One question, if I want to retun the months as alphabitics instead of number should I add <cfif> statement or is there a function for that?
>
> Thanks again

Yes, I'm sure your database date functions could convert the month to an
text name rather then a number. ColdFusion also has a monthAsString()
function that takes the number of a month and returns the string name,
strangely enough.
Known Participant
November 13, 2008
Thanks Ian.
This is what I wanted.
One question, if I want to retun the months as alphabitics instead of number should I add <cfif> statement or is there a function for that?

Thanks again
Inspiring
November 14, 2008
quote:

Originally posted by: andy99
Thanks Ian.
This is what I wanted.
One question, if I want to retun the months as alphabitics instead of number should I add <cfif> statement or is there a function for that?

Thanks again

Google "date functions your db". Different dbs have different functions. They have names like datename, to_char, or convert.
Inspiring
November 13, 2008
Assuming your date column is truly a date column with a date type not a
text column that stores a text string that looks like a date to most
people. Then this will be easy, otherwise it will be much harder and I
would strongly recommend improving your database design.

<cfquery ... name="recSet">
SELECT
year(dateField) AS year,
month(dateField) AS month,
dateField,
nameField

FROM
table

ORDER BY
dateField ASC
</cfquery>

<!---
What that actual functions are for year() and month() will very from
database management system to system. Their documentation is happy to
tell you what they are. All of them have something that handles this
type of conversion.
--->

<cfoutput query="recSet" group="year">
#year#<br>
<cfoutput group="month">
#month#<br>
<cfoutput>
#dateField# #NameField#<br>
</cfoutput>
</cfoutput>
</cfoutput>