Overview
TheFORMAT_TIMESTAMP()
function returns a given timestamp value in a specified format. Its syntax is illustrated below:
#Case 1: Basic FORMAT_TIMESTAMP()
function
The below example uses the FORMAT_TIMESTAMP()
function to convert a given timestamp into a timestamp format as specified in the function arguments.
YYYY
is the four-digit year 2022MM
is the month: 05DD
is the day: 30HH
is the hour: 5MI
is the minute: 30SS
is the second: 04
The format specified in the string can be used in any combination.
Case #2: FORMAT_TIMESTAMP()
function using multiple spaces
The FORMAT_TIMESTAMP()
when given multiple spaces in the input string, omits the spaces and only returns the correct timestamp value. Let’s see how it works using the following example:
Case #3: FORMAT_TIMESTAMP()
function if the input value of the year is less than 4 digits
FORMAT_TIMESTAMP()
will adjust the year to the nearest year value if the input argument has less than the required number of digits i.e., less than 4. To see how it works, look at the example below:
09
has been changed to the nearest four-digit year i.e., 2009
. Similarly, 70
will become 1970
, and 10
will become 2010,
etc.