Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 00BE31337B82 for ; Thu, 21 Apr 2011 16:59:20 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 69635-05 for ; Thu, 21 Apr 2011 19:59:12 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail3.sea5.speakeasy.net (mail3.sea5.speakeasy.net [69.17.117.42]) by mail.postgresql.org (Postfix) with ESMTP id 44607133616B for ; Thu, 21 Apr 2011 16:59:11 -0300 (ADT) Received: (qmail 19603 invoked from network); 21 Apr 2011 19:59:09 -0000 Received: from dhcp184-48-213-189.hil-satdthx.aus.wayport.net (scott_ribe@killerbytes.com@[184.48.213.189]) (envelope-sender ) by mail3.sea5.speakeasy.net (qmail-ldap-1.03) with AES128-SHA encrypted SMTP for ; 21 Apr 2011 19:59:09 -0000 Subject: Re: unix timestamp Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=windows-1252 From: Scott Ribe In-Reply-To: <93361C67E4EE844A80935863A4FF4B6C04E86CB9@Exch2010MB-2.univ.dir.wwu.edu> Date: Thu, 21 Apr 2011 14:59:07 -0500 Cc: "pgsql-admin@postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: <6FC9C366-94F0-4EFC-B882-AA8284020BF3@elevated-dev.com> References: <93361C67E4EE844A80935863A4FF4B6C04E86CB9@Exch2010MB-2.univ.dir.wwu.edu> To: Marc Fromm X-Mailer: Apple Mail (2.1084) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201104/204 X-Sequence-Number: 37385 On Apr 21, 2011, at 2:19 PM, Marc Fromm wrote: > Is there a way to query a unix timestamp date? In the database the = orderdate field is a unix timestamp. > I would like to create the where clause to a query on a specific date = like December 17, 2010. > Select * from orders where orderdate =3D =9112/17/2010=92; I'm assuming by unix timestamp, you mean an integer column with number = of seconds since 1/1/1970. If you're talking about a char column with a = formatted date & time, the answer is similar in spirit but different = details. You've got to make them into the same data type. You can try to = make a date from the unix timestamp, or a timestamp from the date. The epoch function will get you a unix timestamp directly from a date, = but of course that's number of seconds, so then you'd have to compare a = range, and calculating that across daylight savings boundaries could be = tricky. I'd go for turning the timestamp into a date, probably something = like '1970-01-01 00:00:00 UTC'::timestamp + orderdate * interval '1 = second'. Of course you don't say whether the timestamps are local times or UTC, = and whether you want the date based on local or UTC, so you'll have to = figure that part out. Anyway, for more info, see the date & time = functions docs: --=20 Scott Ribe scott_ribe@elevated-dev.com http://www.elevated-dev.com/ (303) 722-0567 voice