Instruction
Fantastic job! It's time to review what we know about date and time in PostgreSQL:
- PostgreSQL uses dates (
'2010-01-01'), times ('13:00:00'), and timestamps ('2010-01-01 13:00:00'). - You can compare the above types with
BETWEENor basic operators like:<,<=,>,>=. - You can specify the resulting order with
ORDER BY. - The
TIMESTAMPdata type allows you to save date and time data in your local time zone. - To get parts of a date or time, use the
EXTRACT()orDATE_PART()functions. - Use the
DATE_TRUNC(x, y)function to truncate the date and time (passed asy) to the given date or time part (passed asx). - Use the
INTERVALoperator to add or subtract a period of date or time. - Use the operator
::to convert data types. - Use the
AGE(x, y)function to return the difference between the current date or between two dates,xandy, specified as arguments. - Use converted time zones with
AT TIME ZONE 'new_timezone'. - Use
TO_CHAR(timestamp, format)to display the date in a given format. - To get the current date and time, use:
CURRENT_TIMESTAMPto get the timestamp with the time zone (orCURRENT_TIMESTAMP(p)wherepis the precision of fractional seconds).NOW()to get date and time with time zone.CURRENT_DATEto get only the date.CURRENT_TIMEto get only the time with the time zone (orCURRENT_TIME(p)wherepis the precision of fractional seconds).
Are you ready to practice what you've learned?
Exercise
Click to continue.



