Below are the keywords to get the date, time, or timestamp. These are reserved words that the system will deliver to you when requested.

Transaction_Timestamp is equivalent to CURRENT_TIMESTAMP but is named to reflect what it returns. For example, statement_Timestamp returns the start time of the current statement. Clock_Timestamp returns the current time, and values can change within a single SQL command.

NOW is a traditional PostgreSQL equivalent to transaction_timestamp(). The Timeofday function returns the current time as a formatted text string rather than a timestamp with a time zone.

Adding or subtracting a number from a date adds or subtracts several days from the date.

When subtracting between two dates, you get the approximate number of days between those dates.

You can use the To_Char function to format dates.

The below examples show how robust the EXTRACT command is at extracting portions of a date, time, or timestamp.

The below examples use the Date_Part function to get the subfields. The text parameter needs to be a string value, not a name, so don’t forget your single quotes.

The below examples use the Date_Trunc function to get the subfields. The text parameter needs to be a string value, not a name, so don’t forget your single quotes. Date_Trunc selects which precision to truncate the input value. The return value is of type timestamp or interval. The valid text The above examples use the Date_Trunc function to get the subfields. The text parameter needs to be a string value, not a name, so don’t forget your single quotes. Date_Trunc selects which precision to truncate the input value. The return value is of type timestamp or interval.

The first example determines the age between two timestamps and the result that uses years, months, and days, and it is of the type INTERVAL. The second example subtracts the single timestamp from the current_date at midnight.

Intervals add or subtract a period from a date at specific intervals. Notice that the interval is aware of the leap year.