Thread: forcing date ordering

forcing date ordering

From
"tab view"
Date:
When I do the following piece of SQL

SELECT DISTINCT to_char(datetimelogged,'dd/mm/yyyy') AS datelogged FROM
logins ORDER BY datelogged DESC;

I don't seem to get the column sorted in date order. How do I force psql to
use date order?

Nige

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


Re: forcing date ordering

From
Michael Glaesemann
Date:
On Sep 6, 2004, at 10:21 PM, tab view wrote:

> SELECT DISTINCT to_char(datetimelogged,'dd/mm/yyyy') AS datelogged
> FROM logins ORDER BY datelogged DESC;
>
> I don't seem to get the column sorted in date order. How do I force
> psql to use date order?

What is the data type of the datetimelogged column?

Michael Glaesemann
grzm myrealbox com


Re: forcing date ordering

From
Tom Lane
Date:
"tab view" <tabview@hotmail.com> writes:
> When I do the following piece of SQL
> SELECT DISTINCT to_char(datetimelogged,'dd/mm/yyyy') AS datelogged FROM
> logins ORDER BY datelogged DESC;

> I don't seem to get the column sorted in date order.

I'd expect that to produce a textual sorting of the to_char strings.

> How do I force psql to use date order?

Sort by the underlying datetimelogged column, which I suppose is of
date or timestamp type ...

            regards, tom lane