Instruction
Nice! Now we will learn more specifiers to convert the date to a new format. Let's look at this query below:
SELECT
id,
TO_CHAR(
launched_timestamp,
'DD Mon YY, HH12:MI:SS.US AM')
AS formatted_launched_ts
FROM aircraft;
This query is for the aircraft with ID of 1 and a launched timestamp of '2014-06-10 07:55:0' and returns this date and time in new format:
10 Jun 14, 07:55:00.000000 AM
Consider the following format patterns:
| Pattern | Description |
|---|---|
DD |
day of month (01-31) |
Mon |
abbreviated capitalized month name (3 chars in English, localized lengths vary) |
YY |
last 2 digits of year |
HHHH12 |
hour of day (01-12) |
HH24 |
hour of day (00-23) |
MI |
minute (00-59) |
SS |
second (00-59) |
US |
microsecond (000000-999999) |
AM, am,PM, pm |
meridiem indicator (without periods) |
A.M., a.m.,P.M., p.m. |
meridiem indicator (with periods) |
You will find more format patterns in the PostgreSQL documentation.
Exercise
Let's show the code and the departure time for each route in a new format 'HH24.MI.SS', where:
HH24is hour in the range 00-24.MIis minute in the range 00-59.SSis second in the range 00-59.
where the time components are separated by a dot. Name the new column formatted_departure_time.



