Type Conversions

by Zoe Reed

Type conversions are functions that allow us to convert fields or a string from one data type to another.

DATE

Converts the argument into a date.

Eg DATE([Order Date]) converts all the order dates into dates.

DATE(“July 1 2004”) and DATE(“01/07/2004”) both return 1 July 2004.

As shown above, if the argument is a string, this must be enclosed by speech marks or quotation marks. If the argument is a field, this is not necessary.

DATETIME

Converts the argument into a datetime.

Eg DATETIME([Order Date]) converts all the order dates into datetimes.

If there is no time in the argument, it will return a datetime with 00:00:00 as the time.

Eg DATE(“July 1 2004 11:15”) returns 1 July 2004 11:15:00.

DATE(“July 1 2004”) returns 1 July 2004 00:00:00.

As shown above, if the argument is a string, this must be enclosed by speech marks or quotation marks. If the argument is a field, this is not necessary.

FLOAT

A float is a number with decimal points.

The float function returns the argument in float format.

Eg. FLOAT(3)=3.000

STRING

Returns the argument as a string.

INTEGER

This function rounds the argument to the closest integer (whole number) towards zero.

Eg INT(3.6) returns 3

INT(3.3) returns 3

INT(-3.6) returns -3

INT(-3.3) returns -3

MAKEDATE

Constructs a date from a specified year, month and day of the month.

Eg MAKEDATE(2023, 3, 30) returns 30 March 2023.

MAKEDATETIME

Constructs a datetime from a specified date expression and time expression.

The date expression and time expression must each be enclosed by # and separated with a comma.

Eg MAKEDATETIME(# 30 3 2023#, #11:15#) returns 30/03/2023 11:15:00

MAKETIME

Constructs a time from specified hours, minutes and seconds.

Tableau does not hold time as its own data type so a date either needs to be attached to the time, or Tableau will attach a date to it.

Eg MAKETIME(2, 15, 30) returns 30/12/1899 02:15:30.