Expressions and code
Work with dates using Luxon in Duaer
Dates in a Duaer expression are Luxon DateTime values. $now and $today already are. The Code node uses native Luxon—format() and plus(amount, unit) do not carry over unchanged.
How a Duaer expression gets a DateTime
$now is the current time. $today is the start of today. An existing string uses DateTime.fromISO, or toDateTime() on the value.
{{ $now.toFormat("yyyy-MM-dd") }}
{{ $json.createdAt.toDateTime().plus(7, "days").toISO() }}Native Luxon in the Code node is different
- format() in an expression is a Duaer extension. In the Code node, format with toFormat().
- In an expression, plus and minus accept (amount, unit), such as plus(7, "days"). Native Luxon in the Code node wants plus({ days: 7 }). Two arguments may not throw, and still will not add the days you wanted.
- Several statements belong in an immediately invoked function. See Transform data with expressions in Duaer.
Questions
How do you get today’s date string in Duaer?
In a Duaer expression, write {{ $now.toFormat("yyyy-MM-dd") }}. $now is a Luxon DateTime. To pin a time zone, call setZone before toFormat.
Why does the same plus call give the wrong result in the Duaer Code node?
A Duaer expression accepts plus(7, "days"). The Code node uses native Luxon and wants plus({ days: 7 }). Two arguments may not throw, and still will not add those 7 days.
In this section
Date transformation methods in Duaer
In a Duaer expression, $now and $today are Luxon DateTime values. Call toDateTime() on a string or number before format, plus, or setZone.
ExpressionsUse convenience methods in Duaer expressions
In a Duaer expression, use $json for the current item, $("Node name") for an earlier node, and $now and $if() for time and conditions.
ExpressionsTransform data with expressions in Duaer
Use expression transformation functions anywhere expressions are supported in Duaer. When you only reshape fields, prepare them in Edit Fields (Set) first.