Skip to main content
penscript provides operators for creating, formatting, comparing, and manipulating dates. These are used for deadline calculations, age-based eligibility rules, contract expiration checks, and time-sensitive automations.

Date Creation: :date

Creates a date from a string or retrieves the current date/time.
Strings in ISO 8601 format ("2024-01-15T00:00:00.000Z") and YYYY-MM-DD format ("2024-01-15") are automatically parsed as dates. The system variable {$today} is also available in inline expressions for the current date.

Date Formatting: :format-date

Formats a date according to a pattern string.

Pattern Characters

Inline Formatting with Pipes

For quick formatting inside strings, use the formatDdMmYyyy pipe:

Date Comparison

Using :cmp

Combine :cmp with dates and the | age pipe for age-based conditions:
All standard comparison modifiers work: :eq, :neq, :gt, :gte/:ge, :lt, :lte/:le.

Inline Date Comparisons

Simple date comparisons can be expressed directly inside strings:
Direct inline comparison patterns:
Combined conditions:

Date Difference: :diff

Calculates the difference between two dates in a specified unit.

Available Comparators

Age Calculation: | age

Calculates the age in years from a date value. Available as an inline pipe.
Commonly combined with :cmp for eligibility rules:

Date Arithmetic: :sum with Dates

Add or subtract time from dates using duration strings. Single duration:
Multiple durations combined:

Supported Duration Units

Raw Numbers and Strings

  • Raw numbers are treated as milliseconds. Negative numbers subtract time.
  • Numeric strings (e.g., "+86400") are treated as seconds.

Building Deadlines

A common pattern — calculate a deadline and format it for display:

Next Steps

Variables & scope

$today and inline pipes

Logic & comparisons

Date-based conditions with :cmp

Numbers & calculations

:sum for date arithmetic

How penscript works

Date examples in automations