From: | Holger Mitterwald <mittehlg(at)coi(dot)de> |
---|---|
To: | William McCracken <will(at)sitestar(dot)com> |
Cc: | pgsql-sql(at)postgreSQL(dot)org |
Subject: | Re: [SQL] Query based on date/time field |
Date: | 1998-08-12 12:50:02 |
Message-ID: | Pine.HPP.3.95.980812134339.4410A-100000@hp00076.ina.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-sql |
On Tue, 4 Aug 1998, William McCracken wrote:
> I am new to SQL and was wondering how I would go
> about selecting records from my database based on
> the age of a date/time stamp.
>
> For example if I wanted to select records older than
> 12 hours or 1 day.
>
> Any help would be appreciated.
Sorry for my late response, but I was on holiday.
I use some statement like this to select entries that are not older than 2
weeks:
SELECT DISTINCT landkreis FROM kneipe WHERE 1209600 >= (date_part('epoch',
current_date) - date_part('epoch',datum));
datum is of type datetime.
what I do is the following: epoch returns the seconds since january 1st
1970 (I think). I substract the timestamp of each record from the current
timestamp (current_date). The result has to be smaller than the duration
for 2 weeks (in seconds, which is 1209600s).
I dont know if there is a better solution, but it works fine.
So long,
Holger
--------------------------------------------------------------------------------
Holger Mitterwald COI-D #### ##### ### CONSULTING FUER OFFICE
COI GmbH Herzogenaurach # # # # UND INFORMATION
Industriestrasse 1 - 3 # # # # MANAGEMENT GmbH
D-91074 Herzogenaurach #### ##### ### Tel.: 09132/82-3811
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas Zeugswetter | 1998-08-12 12:52:20 | Re: AW: [HACKERS] Rule system |
Previous Message | Aleksey Dashevsky | 1998-08-12 12:47:45 | Re: [SQL] Query based on date/time field |
From | Date | Subject | |
---|---|---|---|
Next Message | Dimitri | 1998-08-12 12:59:02 | Re: [SQL] Subquery problems |
Previous Message | Aleksey Dashevsky | 1998-08-12 12:47:45 | Re: [SQL] Query based on date/time field |