Thursday, January 18, 2007

(extract('epoch' from now()) - extract('epoch' from created)) < 14400

have a column named created tat says when the row was inserted
i want to choose say the columns inserted in the last 4 hrs
10 hrs or 1 day
i cudnt find out how to do it
select * from polls where created .. then waht
are the random database queries too slow
select * from polls.... where... and extract('epoch' from created) < 14400
wat is epoch
7:04:02 pm
where the epoch field is the time in seconds, since 1970
and 1440 is how many seconds in 4 hours
7:04:23 pm

is there a field in minutes or hours
7:04:39 pm
that needs to be and (now() - extract('epoch' from created)) < 14400
there is a field to get the day, hour, minute,
year, month, but those are absolute (==)
if you want something that is 4 hours ago or newer, then you need to do
interval arithmetic yourself by taking the current time
crap that still aitn it
and (extract('epoch' from now()) - extract('epoch' from created)) < 14400
so this takes the absolute time, in seconds now and subtracts the
absolute time from when it was created
which if smaller than 60*60*4, is under 4 hours
7:07:41 pm

7:08:22 pm
there is the age(timestamp) function but that displays pretty printing
not very usefl for a query

No comments: