Projects often have a mix of different types, and it is common to require conversion between different types. Which conversion is required depends on which types are involved.
Converting from text is primarily done using the from text(..) and from text to(..) functions. The destination type that is being converted from needs to be known ahead of time. Often this is apparent from the context and thus the simpler from text(..) can be used. In cases where this is not possible, you will be prompted to use from text to(..) instead, where the type is specified.
Converting to text is primarily done using the to text(..) function. This converts each type into its standard text form. Several examples are below. Most types are straightforward, although note that times convert to the 24-hour clock and dates convert to the ISO 8601 YYYY-MM-DD format.
There are three main types of conversion (with more examples below):
convert unit({s}, 1.25{minute})
will return 75{s} (s being the unit for seconds, min being minutes).
row * 1{minute}
. More examples are below
12{hour} / 1{hour}
will give the result 12 without units.
Converting between different date and time types is usually a matter of composing, decomposing or differencing.
Composing means making smaller parts into larger, for example converting a Date and a Time into a DateTime, or converting a year and a month into a DateYM. Such functions are:
Decomposing larger parts into smaller items, for example extracting the Date from a DateTime, or the year from a Date. Such functions are:
Differencing means comparing two items of the same date or time type, to work out the distance between them. Such functions are: