Functions
CAST to rename a column, FORMAT and TO_DATE to format dates.
Three functions can be used inside fields(...). Upper or lower case names both work.
CAST — rename a column#
from('members', 'm').fields({CAST('m.id', 'no'), CAST('m.name', 'first_name')});The id field comes back as a column named no. The value does not change; only the column's name does.
FORMAT — format a date#
from('members', 'm').where({'m.name': 'Osman'}).fields('m.name', FORMAT('m.birth_date', 'dd-mm-yyyy'));FORMAT only applies to date and time fields (date, datetime, time, timestamp). The column keeps the field's name; wrap it in CAST to give it another one:
from('members').fields(CAST(FORMAT('created_at', 'dd.mm.yyyy hh:ii'), 'joined'));# error: FORMAT applies to date and time fields; 'name' is string
from('members').fields(FORMAT('name', 'dd-mm-yyyy'));TO_DATE — turn an integer timestamp into a date#
Many systems store time as an integer (a Unix timestamp). TO_DATE turns such a field into a readable date:
from('members', 'm')
.where({'m.login_at': {ne: null}})
.fields('m.name', TO_DATE('m.login_at', 'dd-mm-yyyy hh:ii:ss'));- The value can be in seconds or milliseconds. Values with an absolute value of 10¹² or more are treated as milliseconds.
TO_DATEalso works on date fields; there it behaves likeFORMAT.
Format tokens#
| Token | Meaning | Example |
|---|---|---|
yyyy | year | 2026 |
yy | two-digit year | 26 |
mm / MM | month | 10 |
dd | day | 30 |
hh / HH | hour (00–23) | 14 |
ii | minute | 05 |
ss | second | 09 |
Separators are - / . : , T and space. 'dd-mm-yyyy hh:ii:ss' produces 30-10-2026 14:05:09.
Times are written in UTC. There is no time zone option yet.