Skip to content

Date (mash.date)

mash.date · Utilities

mash.date makes dates. Every date it gives you is a Date with its own methods for adding, subtracting, comparing and formatting. Use it for due dates, ages, “files older than 30 days”, and the dates you write into reports and fields.

Four ways in. now() is this moment. today(), tomorrow() and yesterday() are midnight on those days. parse("2026-11-03 14:05") reads text, and understands plain English such as "3 November 2026" or "next monday". create(2026, 11, 3, 14, 5) builds one from year, month, day, hour and minute.

A date that can’t be read is an error. parse("not a date") raises one, so catch it with an error block when the text comes from outside.

The script’s clock is the server’s. If the time of day matters, show the offset with format("Y-m-d H:i P").

Dates change in place. d.addDays(5) moves d itself. set b to a doesn’t copy a date, it gives the same date another name. Make a copy with d.copy() before you change anything you want to keep. See the Date page for the methods.

Work out a due date without disturbing the start:

set start to mash.date.parse("2026-11-03")
set due to start.copy().addDays(30)
printline "Start: {{start.format('Y-m-d')}}"
printline "Due: {{due.format('Y-m-d')}}"
Start: 2026-11-03
Due: 2026-12-03

Build a date and read it back in a friendly format:

set d to mash.date.create(2026, 11, 3, 14, 5)
printline d.format("D j M Y, H:i")
printline d.copy().endOfMonth().format("Y-m-d")
Tue 3 Nov 2026, 14:05
2026-11-30

Read text that might not be a date:

set when to null
set when to mash.date.parse("next tuesday-ish")
error
printline "Couldn't read that date"
set when to mash.date.today()
end
printline when.format("H:i")
Couldn't read that date
00:00

Find out how old a file is:

set doc to mash.files.get("Finance", "Invoices/INV-2041.pdf")
if doc.modified.diffInDays(mash.date.now()) is more than 30
printline "{{doc.name}} is over 30 days old"
end
  • diffInDays and its relatives are signed. a.diffInDays(b) is positive when b is later than a and negative when it’s earlier. Pass true as a second argument for the plain distance, a.diffInDays(b, true). The answer can have a fraction (4.5 hours).
  • Month ends. addMonth() from 31 January lands in March. addMonthNoOverflow() stops at the end of February.
  • Plain mash.date.parse of a date with no time is midnight. Compare days with isSameDay, not ==.
  • The rounding flags (mash.date.round, floor and ceil) are numbers that some date methods accept. You won’t need them often.

Talking to the outside world, Values and types for how dates copy, and the Date type.

Create and process date objects

NameTypeDescription
ceil
floor
round
date.create(args?: mixed) → Date

Create a date from components.

date.now() → Date

Get the current date and time.

date.parse(string: string) → Date

Parse a date string.

date.today() → Date

Get the start of today.

date.tomorrow() → Date

Get the start of tomorrow.

date.yesterday() → Date

Get the start of yesterday.