TODATE

The TODATE function formats a datetime field according to the specified format.

In this article:

Sample Usage

TODATE(response_time, 'NANOS', '%Y-%m-%d') 
TODATE(create_time, 'DECIMAL_DATE', '%Y')

Syntax

TODATE(field_expression, input_date_format, output_date_format)

Input formats

input_date_format is optional if field_expression is correctly configured as a semantic date.

TODATE accepts the following input format strings.

  • 'BASIC' - Supported format YYYY/MM/DD-HH:MM:SS
  • 'DEFAULT_DASH' - Supported format YYYY-MM-DD [HH:MM:SS[.uuuuuu]]
  • 'DEFAULT_SLASH' - Supported format YYYY/MM/DD [HH:MM:SS[.uuuuuu]]
  • 'DEFAULT_DECIMAL' - Supported format YYYYMMDD [HH:MM:SS[.uuuuuu]]
  • 'RFC_1123' - Sample format: Sat, 24 May 2008 20:09:47 GMT
  • 'RFC_3339' - Sample format: 2008-05-24T20:09:47Z
  • 'SECONDS' - Seconds since epoch
  • 'MILLIS' - Millis since epoch
  • 'MICROS' - Micros since epoch
  • 'NANOS' - Nanos since epoch
  • 'JULIAN_DATE' - Days since epoch
  • 'DECIMAL_DATE' - Same as 'DEFAULT_DECIMAL'
  • Any valid strptime format as string

Output formats

TODATE accepts the following output format strings:

  • "%Y" - year
  • "%m" - month
  • "%d" - day
  • "%W" - yearweek number
  • "%w" - day of week
  • "%H" - hour
  • "%M" - minute

Examples

  • YYYYMMDD (canonical Data Studio date): "%Y%m%d"
  • Date Hour: "%Y%m%d%H"
  • Year Week: "%Y%W"
  • Year Month: "%Y%m"

Notes

  • Return type: String
Was this article helpful?
How can we improve it?