When I send a form on my web, the insert query saves the current date on my DB using the function now().
Now, I'm trying to get this column in minute format to calculate other thinks that I need, but I don't know how to do that.
For example, I have this:
"2013-05-08 08:30:00"
And I want this (now 8.50):
"20" <- In minutes
Thanks
OK, let's suppose you have a table with a timestamp:
CREATE TABLE ex (t timestamp);
INSERT INTO ex VALUES ('2013-05-08 8:30'::timestamp);
And you want the difference in minutes between the column t
and now()
. You can get that using the extract
function:
SELECT extract(epoch from (now() - ex.t)) / 60 FROM ex;
epoch
is the number of seconds from the "epoch" for date
and timestamp
types, but is't just the number of seconds in the interval for interval
types. By dividing it by 60 you get what you want (if you want an integer number of minutes just trunc
it.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With