FORMAT_DATETIME

Converts a datetime value into a string.

Syntax

FORMAT_DATETIME(datetime, format)

Arguments

NameTypeDescriptionDefault Value

datetime

timestamp

A datetime value.

format

string

A format string that is compatible with JodaTime’s pattern: http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html

Examples

datetimeformatOutput

timestamp '2017-09-25 22:11:00'

'yyyy/MM/dd HH:mm:ss.SSS'

2017/09/25 22:11:00.000

timestamp '2018-03-10 08:12:45'

'yyyy/MM/dd'

2018/03/10

timestamp '2019-10-20 08:55:12.450'

'HH:mm:ss.SS'

08:55:12.45

timestamp '2018-03-10 08:55:12.450'

'E'

Sat

Transformation job example

SQL

CREATE JOB function_operator_example
    ADD_MISSING_COLUMNS = true
AS INSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data 
  MAP_COLUMNS_BY_NAME
    SELECT datetime, format,
        FORMAT_DATETIME(datetime, format) AS Output
    FROM default_glue_catalog.upsolver_samples.orders_raw_data
    LET datetime = timestamp '2017-09-25 22:11:00',
        format = 'yyyy/MM/dd HH:mm:ss.SSS'
    WHERE $commit_time BETWEEN run_start_time() AND run_end_time()
    LIMIT 1;

Query result

datetimeformatOutput

timestamp '2017-09-25 22:11:00'

'yyyy/MM/dd HH:mm:ss.SSS'

2017/09/25 22:11:00.000

Last updated