Formulas: Date Math

Formulas: Date Math

How to use date functions in Layer formulas to calculate time differences, next due dates, overdue flags, and asset age.

Mike Lee

Thursday, May 7, 2026

Layer formula fields support a set of built-in date functions. These functions let you add or subtract intervals from a date, compare dates, extract components such as the year or month, and format a date as a string. Layer treats dates and datetimes as a single date type. Time-of-day functions are available when the underlying field is configured as a datetime.

This article covers the date functions available in formula v2, common patterns built from them, and the behaviour to know about Layer's date model before you start.

Available date functions

Layer formulas group the date functions into three categories.

Add and subtract intervals

Each unit has its own add or subtract function. There is no generic DATE_ADD(date, n, unit) form.

Function

Description

DATEADDDAYS(date, days)

Adds a number of days

DATEADDWEEKS(date, weeks)

Adds a number of weeks

DATEADDMONTHS(date, months)

Adds a number of months

DATEADDYEARS(date, years)

Adds a number of years

DATEADDHOURS(date, hours)

Adds a number of hours

DATEADDMINUTES(date, minutes)

Adds a number of minutes

DATEADDSECONDS(date, seconds)

Adds a number of seconds

DATESUBTRACTDAYS(date, days)

Subtracts a number of days

DATESUBTRACTWEEKS(date, weeks)

Subtracts a number of weeks

DATESUBTRACTMONTHS(date, months)

Subtracts a number of months

DATESUBTRACTYEARS(date, years)

Subtracts a number of years

DATESUBTRACTHOURS(date, hours)

Subtracts a number of hours

DATESUBTRACTMINUTES(date, minutes)

Subtracts a number of minutes

DATESUBTRACTSECONDS(date, seconds)

Subtracts a number of seconds

The second argument can be a number literal or a number field reference. Negative values are supported.

Compare dates

Function

Description

DATEISBEFORE(date1, date2)

Returns TRUE when date1 is earlier than date2

DATEISAFTER(date1, date2)

Returns TRUE when date1 is later than date2

DATEISSAME(date1, date2)

Returns TRUE when both dates are identical, including the time component

DATEISSAMEDAY(date1, date2)

Returns TRUE when both dates fall on the same calendar day

DATEISSAMEWEEK(date1, date2)

Returns TRUE when both dates fall in the same ISO week

DATEISSAMEMONTH(date1, date2)

Returns TRUE when both dates fall in the same calendar month

DATEISSAMEYEAR(date1, date2)

Returns TRUE when both dates fall in the same calendar year

DATEISSAMEHOUR(date1, date2)

Returns TRUE when both dates fall in the same hour

DATEISSAMEMINUTE(date1, date2)

Returns TRUE when both dates fall in the same minute

Extract components and format

Function

Description

YEAR(date)

Returns the four-digit year

MONTH(date)

Returns the month as a number 0 (January) through 11 (December)

WEEK(date)

Returns the ISO week number, 1 through 53

DAY(date)

Returns the day of the week as a number 0 (Sunday) through 6 (Saturday)

HOUR(date)

Returns the hour as a number 0 through 23

ISWEEKDAY(date)

Returns TRUE when the date falls Monday through Friday

ISWEEKEND(date)

Returns TRUE when the date falls on Saturday or Sunday

DATETOSTRING(date, format)

Converts a date to a string using date-fns format tokens such as yyyy-MM-dd

The current date and time is available through the NOW() utility function. Layer does not include a separate TODAY() helper. Pass NOW() to the comparison functions when you need to compare against the current moment.

Common patterns

Next maintenance due date

Add a fixed interval to the date a recurring task was last performed.

DATEADDDAYS({Last Serviced}, 365)

If the interval is itself stored as a number field, reference that field as the second argument.

DATEADDDAYS({Last Serviced}, {Maintenance Interval (days)})

Reminder date one week before an inspection

DATESUBTRACTDAYS({Inspection Date}, 7)

Overdue flag

Use a date comparison inside IF to label an element as overdue when its due date has passed.

IF(DATEISBEFORE({Due Date}, NOW()), "Overdue", "On track")

Closed in the same week as reported

DATEISSAMEWEEK({Closed Date}, {Reported Date})

Format an inspection date for display

DATETOSTRING({Inspection Date}, "MMMM dd, yyyy")

Year of installation as a number

YEAR({Installation Date})

Branch by weekday or weekend

IF(ISWEEKEND({Scheduled Date}), "Reschedule to weekday", "On schedule")

Computing the difference between two dates

Layer formula v2 does not include a DATEDIFF style function that returns the number of days, weeks, or years between two dates as a single value. To express "is this after that," compare the dates with DATEISBEFORE or DATEISAFTER. To group elements by relative time periods, compare them with DATEISSAMEDAY, DATEISSAMEWEEK, DATEISSAMEMONTH, or DATEISSAMEYEAR.

If you need a numeric duration on the element, the most direct option is to store the duration as a number field rather than computing it inside a formula.

Things to know

MONTH and DAY are zero-indexed. MONTH(2026-01-15) returns 0, not 1. DAY returns the day of the week, not the day of the month, and counts Sunday as 0.

Month arithmetic at boundaries. DATEADDMONTHS(2026-01-31, 1) returns 2026-02-28 because February has fewer days. Test boundary cases when your formulas depend on month-level precision.

NOW() is a datetime in UTC. Comparisons that mix a datetime field and a date-only field can produce unexpected results around midnight. Match the field type, or pass both through DATEISSAMEDAY.

Field references in the visual editor. The visual formula editor inserts field references when you drag or select a field. The {Field Name} notation in the examples above is shorthand for communicating structure in writing.

Additional resources