Click to See Complete Forum and Search --> : dare sort problem


pj-away
09-18-2003, 06:02 AM
I have a problem with order by s_date

The code I have written is :-

<?
$today = date("Y-n-j");
$realtoday = date("j-n-Y");
$conn = db_connect();
mysql_select_db("somedatabase");

$query = "select DATE_FORMAT(s_date, '%Y %m %d')as s_date, DATE_FORMAT(s_date, '%d %m %Y')as n_date, DATE_FORMAT(f_date, '%d %m %Y')as f_date, e_number, s_location, notes, map_ref, info from sda_events where f_date > '".$today."' order by s_date" ;
$result = mysql_query($query);

The f_date > $today appears to work ok

But doing an order by s_date sorts in day order and does not appear to take into account of the month and year !

Can anyone help ?

thanks

Paul

NB I need to show dates in DDMMYYYY format

eomer
09-19-2003, 10:44 PM
Couple of things. One we need to know what MySQL version that you are using (some versions had some weird side-effects sorting on dates). Two if you can send us the table structure. i.e.

CREATE TABLE table_name (
row_id int(255) NOT NULL auto_increment,
row_1 int(25) default NULL,
row_2 int(9) NOT NULL default '0',
row_3 varchar(255) default NULL,
row_4 timestamp(14) NOT NULL,
row_5 tinytext,
row_6 varchar(15) NOT NULL default '',
PRIMARY KEY (row_id)
) TYPE=MyISAM;


This will give us a little bit more to run off of, and help you out.

eomer
09-19-2003, 10:46 PM
oops...mod...I hit the wrong button... can you put this under "dare sort problem".

Sorry...it's been a really long day.

pyro
09-19-2003, 10:54 PM
Sure thing. Merged them together...

pj-away
09-22-2003, 02:34 PM
Thanks

MySql Version 3.23.33

Table is :-
CREATE DATABASE /*!32312 IF NOT EXISTS*/ sdadatabase;
USE sdadatabase;
CREATE TABLE sda_events (
s_date date NOT NULL,
f_date date NOT NULL,
e_number tinytext NOT NULL,
s_location tinytext NOT NULL,
notes tinytext,
map_ref tinytext,
info tinytext,
PRIMARY KEY (s_date)
) TYPE=MyISAM;


Yours

Paul