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".
2 Answers
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'
);
2 Comments
user1298426
Thanks. I tried it & it's working fine but my with this approach I am facing group by clause issue. I updated the problem statement & descrption. Please have a look
user1298426
created different thread related to this question stackoverflow.com/questions/23063314/…
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
3 Comments
user1298426
Thanks. I tried it & it's working fine but my with this approach I am facing group by clause issue. I updated the problem statement & descrption. Please have a look
user1298426
created different thread related to this question stackoverflow.com/questions/23063314/…