PostgreSQL Date time data types are further classified into 4 types, such as:
- DATE
- TIMESTAMP
- TIMESTAMP WITH TIME ZONE
- TIMESTAMP WITH LOCAL TIME ZONE
Date and time information will be stored in
number
and
character
datatypes. The information is represented in seconds, minutes, hours, date, month, years and decades.
S.NO |
Function Name |
Purpose |
1 |
NEW_TIME; |
Returns the time/day value from a period zone specified by the client. |
2 |
NEXT_DAY(x,y); |
Returns the date time of the following day after x. |
3 |
LAST_DAY(X); |
Returns the most recent day of the month. |
4 |
ADD_MONTHS(x,y); |
Adds y months to x. |
5 |
MONTHS_BETWEEN(x,y); |
Returns the number of months between x and y. |
6 |
SYSDATE(); |
Returns the present date time. |
7 |
TRUNC(x[,unit]); |
Truncates x. |
8 |
ROUND(x[,unit]); |
Rounds x; |
TIMESTAMP is used to store the exact time values. It will store the year, month and day of the datatype along with hours, minutes and seconds. The TIMESTAMP is an expansion of DATE Datatype.
S.NO |
Function Name |
Purpose |
1 |
LOCALTIMESTAMP(); |
Returns a TIMESTAMP consisting appropriate time in the session time zone. |
2 |
SYSYIMESTAMP(); |
Returns TIMESTAMP WITH TIME ZONE consisting the current database time along with the database time zone. |
3 |
CURRENT_TIMESTAMP(); |
Returns TIMESTAMP WITH TIME ZONE consisting the current session time along with the session time zone. |
4 |
TO_TIMESTAMP_TZ(x,[format]); |
Changes the string x to TIMESTAMP WITH TIMEZONE. |
5 |
TO_TIMESTAMP(x,[format]); |
Change the string x to TIMESTAMP. |
6 |
SYS_EXTRACT_UTC(X); |
Changes the TIMESTAMP WITH TIMEZONE x to a TIMESTAMP consisting the date and time in UTC. |
7 |
FROM_TZ(X,time_zone); |
Changes the TIMESTAMP x and time zone indicated by time_zone to a TIMESTAMP WITH TIMEZONE. |
TIMESTAMP WITH TIME ZONE is a variant of TIMESTAMP that comprises of a period zone region or time zone offset character & values. The offset time zone is the difference between the inclusive time zone and the local time zone.
TIMESTAMP[(fractional_seconds_precisions)]WITH TIME ZONE
Fractional_seconds_precisions => Determines the number of digits in fractional parts.
Eg:TIMESTAMP '1999-01-31 09:25:56:66 +02:00'
TIMESTAMP WITH LOCAL TIME ZONE
TIMESTAMP WITH LOCAL TIME ZONE is considered as another variant of TIMESTAMP that contains a period zone balance in its qualities.
TIMESTAMP[(fractional_seconds_precisions)] WITH LOCAL TIME ZONE
Fractional_seconds_precisions => Determines the number of digits in fractional parts.
TIMESTAMP => No literal TIMESTAMP exists