Select Content by date

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
amsterdam
Forum Newbie
Posts: 5
Joined: Sun Mar 16, 2008 8:04 pm

Select Content by date

Post by amsterdam »

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.
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: Select Content by date

Post by mikemike »

The issue is how you store the dates, the way I see it there are two main ways of storing dates:

1. As a MySQL timestamp (hh:mm:ss yyyy-mm-dd)
2. As a UNIX timestamp (seconds from epoch (jan 1st 1970): 1245678912)

I normally use option 2 but it's often a matter of preferrance. Both will allow you to use an ORDER BY statement in your queries.
Post Reply