Forum Moderators: coopster

Message Too Old, No Replies

Sql Query Question

         

ajs83

1:40 am on Mar 10, 2005 (gmt 0)

10+ Year Member



I want to to have the code sort everything by name where all the dates match up, but the date is entered in the db like 5/01/05 and the code seems to gets stuck on the /, how do you get around that?

Here's what I had

$query="SELECT * FROM title ORDER BY name WHERE date LIKE 5/%";

RyanM

1:48 am on Mar 10, 2005 (gmt 0)

10+ Year Member



$query="SELECT * FROM title ORDER BY name WHERE date LIKE '%-5-%'";

the date format goes year-month-day

ajs83

1:56 am on Mar 10, 2005 (gmt 0)

10+ Year Member



I'd prefer the dates to be in the MM/DD/YYYY format, is that possible?

RyanM

3:29 am on Mar 10, 2005 (gmt 0)

10+ Year Member



Its just the way that databases store their dates internally. I dont know if there is much that you can do about it.

coopster

12:49 pm on Mar 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Most databases will store a column of type DATE in a default format. 9 times out of 10, it is ISO (yyyy-mm-dd) which makes it easy to sort, etc. Most databases will also have loads of nice functions to operate on DATE column types in addition to the SQL standards.

Do yourself a favor and store date data as a DATE column type in your database. If not, then you will have to use a LIKE predicate or SUBSTRING and other tricks to get your date information out of the database in the format and order that you desire, jumping through hoops all the way ...