From: | David Fetter <david(at)fetter(dot)org> |
---|---|
To: | BlackMage <dsd7872(at)uncw(dot)edu> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Order By Date Question |
Date: | 2009-09-08 15:53:58 |
Message-ID: | 20090908155358.GH3738@fetter.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, Sep 08, 2009 at 06:29:28AM -0700, BlackMage wrote:
>
> I have a question about ordering by date. I have a table with two fields and
> some date
>
> Name(character varying) | Event_Date(timestamp with timezone)
> A | 2009-09-10 5:30:00
> B | 2009-09-10- 00:00:00
> C | 2009-09-11 17:30:00
> D | 2009-09-11 07:30:00
>
>
> I want to order by date and then by name, so I want the result A,B,C,D. The
> problem is when I do a 'SELECT * FROM table_name ORDER BY Event_Date, DESC',
> it includes the actual time (HH:MM:SS) so the order comes out B,A,D,C.
>
> So what I am asking is how do I order only by the date? YYYY-MM-DD?
Because you're using timestamp with time zone, you need to tread
carefully, as casting is full of scare. One way to tread carefully is
to
ORDER BY date_trunc('day', "Event_Date"), "Name"
Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com
Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
From | Date | Subject | |
---|---|---|---|
Next Message | Kristian Larsson | 2009-09-08 15:58:01 | Re: Adding integers ( > 8 bytes) to an inet |
Previous Message | Kristian Larsson | 2009-09-08 15:49:02 | Re: Adding integers ( > 8 bytes) to an inet |