Thursday, April 4, 2013

Additions with timestamp in postgresql

To add to the hours, minutes, seconds, day, month or year of a timestamp, the function i used in my project is :
select (timestamp '2013-01-01 08:56:15' +(interval '1 hour'));
this can be used in a stored procedure or function that we can make it use for our own projects as we need.
In functions just use variables which are predefined with its datatype, like
hour_count interval;
date_to_add timestamp;
date_result timestamp;
date_to_add := '2013-01-01 08:56:15'
hour_count : = '1 hour';
date_result := (date_to_add + hour_count);

when we use it with predefined variables no need to cast it as it is in the select statement.

No comments: