Jump to content

help ordering by date


webguy262

Recommended Posts

Trying to find events prior to today's date, and order them chronologically, either asc or dsc.

 

Here's what I've got, but they display out of order.

 

What am I missing?

 

$today = date("Ymd");

$query = "SELECT title, link, chapter, DATE_FORMAT(start_date, '%M %d,
%Y') AS start_date, DATE_FORMAT(start_date, 'Ymd') AS chrono, city, state
FROM events_calendar WHERE start_date < $today  order by chrono";

Link to comment
Share on other sites

The format string in the following is not valid - DATE_FORMAT(start_date, 'Ymd') AS chrono, but that whole term is unnecessary. Also, I am not sure what the results of using an alias of start_date when there is a column by that name would be.

 

What is the format of your start_date column - DATE or DATETIME?

 

Once I know what start_date is, I can show you a very simple query to do what you want.

Link to comment
Share on other sites

This should give the same results -

 

$query = "SELECT title, link, chapter, DATE_FORMAT(start_date, '%M %d,
%Y') AS date, city, state
FROM events_calendar WHERE start_date < CURDATE() order by start_date";

 

Your can use ORDER BY with a DATE type directly and CURDATE() (and CURRENT_DATE, CURRENT_DATE()) give you the date directly (no need for any slow php code.)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.