0
0
PostgreSQLquery~5 mins

TO_CHAR for date formatting in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the TO_CHAR function do when used with dates in PostgreSQL?
TO_CHAR converts a date or timestamp into a string formatted according to the pattern you specify.
Click to reveal answer
beginner
How would you format a date to show only the year using TO_CHAR?
Use TO_CHAR(date_column, 'YYYY') to get the year as a four-digit string.
Click to reveal answer
beginner
What format pattern would you use with TO_CHAR to display the full month name?
Use 'FMMonth' in the format string to display the full month name without padding, e.g., TO_CHAR(date_column, 'FMMonth').
Click to reveal answer
intermediate
Explain the difference between 'MM' and 'Mon' in TO_CHAR date formatting.
'MM' returns the month as a two-digit number (01-12), while 'Mon' returns the abbreviated month name (Jan, Feb, etc.).
Click to reveal answer
beginner
How can TO_CHAR help when you want to display a date in a custom format like 'DD-MM-YYYY'?
You specify the format string 'DD-MM-YYYY' in TO_CHAR to get the date as day-month-year with dashes, e.g., TO_CHAR(date_column, 'DD-MM-YYYY').
Click to reveal answer
Which TO_CHAR format pattern returns the full name of the day of the week?
A'Day'
B'Dy'
C'DD'
D'D'
What will TO_CHAR(current_date, 'YYYY-MM-DD') return?
AMonth-Day-Year as numbers separated by dashes
BA timestamp with time included
CDay-Month-Year as numbers separated by dashes
DYear-Month-Day as numbers separated by dashes
If you want to show the month as a two-digit number, which format should you use?
A'Mon'
B'MM'
C'Month'
D'YY'
Which TO_CHAR pattern returns the last two digits of the year?
A'YYYY'
B'Y'
C'YY'
D'Year'
What does TO_CHAR(timestamp, 'HH24:MI:SS') format?
AHour in 24-hour format with minutes and seconds
BHour in 12-hour format with minutes and seconds
COnly minutes and seconds
DOnly hour and seconds
Describe how TO_CHAR can be used to format a date to show the day, abbreviated month, and year.
Think about how to combine day, month abbreviation, and year in one format.
You got /3 concepts.
    Explain the difference between 'MM' and 'Mon' in TO_CHAR date formatting and when you might use each.
    Consider readability vs sorting needs.
    You got /3 concepts.