Click to See Complete Forum and Search --> : Order selected content by date


amsterdam
06-01-2009, 06:16 PM
Hi,

I have made a form that users can add events. When i display all the events I am trying to order the events by the event date. More specifically I want to order the next upcoming event date that the user inputed.

For example todays date is 6-1-09 and there are events scheduled for 6-23-09, 6-3-09, and 7-12-09. The event should be order like: 6-3-09, 6-23-09, 7-12-09.


Also i would like select past event dates. Date that were schedule that have past the current date.

Any help would be greatly appreciated.

felgall
06-01-2009, 10:26 PM
The first step is to make sure that the field that you are saving the dates in the database in have a type of date. That will then mean that you can easily order the retrieved data by date and select date ranges as well as being able to format it in whatever format you want the date in simply using the format command as part of the retrieval. The only other change you then need to make is to rearrange the dates to be in one of the formats that SQL recognises when you insert them.

You will only have problems if you try to save the dates as text instead of as dates.

amsterdam
06-01-2009, 10:57 PM
Thanks. That is exactly what I needed. I am using datetime. Thanks Again.