I want to add the QUARTER
to the TIMESTAMP
in PostgreSQL 9.3 version.
For adding:
SELECT TIMESTAMP '2016-01-01' + INTERVAL '01 QUARTER';
For remove:
SELECT TIMESTAMP '2016-01-01' - INTERVAL '01 QUARTER';
********** Error ********** ERROR: invalid input syntax for type interval: "01 QUARTER" SQL state: 22007 Character: 42
This can be done in PostgreSQL using the AGE() function. This function takes in two timestamps as arguments and then returns the interval between them.
In PostgreSQL the interval data type is used to store and manipulate a time period. It holds 16 bytes of space and ranging from -178, 000, 000 years to 178, 000, 000 years. It also has additional attribute called “precision (denoted by p)” that can be used to set the level of precision in the query results.
The PostgreSQL CURRENT_TIMESTAMP() function returns the current date and time with time zone. It is important to note that the time and time zone returned by this function is from the time the transactions start.
You can change the format in the postgresql. conf file. The date/time styles can be selected by the user using the SET datestyle command, the DateStyle parameter in the postgresql. conf configuration file, or the PGDATESTYLE environment variable on the server or client.
That's because is not among supported units for quarter
interval
input. The manual:
unit is
microsecond
,millisecond
,second
,minute
,hour
,day
,week
,month
,year
,decade
,century
,millennium
, orabbreviations
or plurals of these units;
Use '3 month'
(or similar) instead:
SELECT timestamp '2016-01-01' + interval '3 month';
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