Reputation: 3717
Say I have column of type dateTime with value "2014-04-14 12:17:55.772" & I need to subtract seconds "2" seconds from it to get o/p like this "12:17:53".
Upvotes: 13
Views: 19922
Reputation:
Postgres does not have a dateTime
data type. I assume you mean a timestamp
.
You can subtract an "interval" with the desired length from that column:
select the_timestamp_column - interval '2' second
from the_table
More about intervals in the manual
More about the operators available for date
and timestamp
columns in the manual
Upvotes: 6
Reputation: 125524
select '2014-04-14 12:17:55.772'::timestamp - interval '2 seconds';
For greater flexibility it is possible to mutiply the interval
select '2014-04-14 12:17:55.772'::timestamp - 2 * interval '1 second';
If you want to truncate to the second
select date_trunc(
'second',
'2014-04-14 12:17:55.772'::timestamp - interval '2 seconds'
);
Upvotes: 26