Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Recordset Date ordering

Participant ,
Feb 06, 2009 Feb 06, 2009

Copy link to clipboard

Copied

Hi,
I have a date field in my database that displays the date a task was posted. But when I ORDER BY date it will only order the date by the DAY only.

The problem is that I get these values:
02/02/09
03/12/08

I want it to beable to sort it out by the year also.

So have 08 above 09

Is there anything I can do?

TOPICS
Server side applications

Views

436
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 06, 2009 Feb 06, 2009

Copy link to clipboard

Copied

The_FedEx_Guy wrote:
> Hi,
> I have a date field in my database that displays the date a task was posted.
> But when I ORDER BY date it will only order the date by the DAY only.
>
> The problem is that I get these values:
> 02/02/09
> 03/12/08
>
> I want it to beable to sort it out by the year also.
>
> So have 08 above 09
>
> Is there anything I can do?

What datatype is your date column in your database?

Dooza
--
Posting Guidelines
http://www.adobe.com/support/forums/guidelines.html
How To Ask Smart Questions
http://www.catb.org/esr/faqs/smart-questions.html

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 10, 2009 Feb 10, 2009

Copy link to clipboard

Copied

I am using varchar. I was trying to avoid the YYYY format.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 06, 2009 Feb 06, 2009

Copy link to clipboard

Copied

.oO(The_FedEx_Guy)

> I have a date field in my database that displays the date a task was posted.
>But when I ORDER BY date it will only order the date by the DAY only.
>
> The problem is that I get these values:
> 02/02/09
> 03/12/08
>
> I want it to beable to sort it out by the year also.
>
> So have 08 above 09
>
> Is there anything I can do?

(assuming MySQL)

First make sure that you use the correct type for the date column,
either DATE or DATETIME. Then use ORDER BY on the date as it is stored
in the database, not on some formatted output. If you have something
like this for example

SELECT
...,
DATE_FORMAT(yourDate, '...') AS yourDate
FROM ...
WHERE ...
ORDER BY yourDate

you'll get the wrong result. You have to give the formatted date another
alias name, so that you can still access the raw date in the table:

SELECT
...,
DATE_FORMAT(yourDate, '...') AS yourFormattedDate
FROM ...
WHERE ...
ORDER BY yourDate

Now ORDER BY will work correctly on the raw date, which is YYYY-MM-DD in
case of MySQL.

HTH
Micha

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 10, 2009 Feb 10, 2009

Copy link to clipboard

Copied

how do I get the date dd-mm-yy?
I dislike looking at the year first. :'(

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 10, 2009 Feb 10, 2009

Copy link to clipboard

Copied

LATEST
.oO(The_FedEx_Guy)

>how do I get the date dd-mm-yy?
>I dislike looking at the year first. :'(

DATE_FORMAT() ?

Micha

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines