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.
How it works
Section titled “How it works”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.
Common tasks
Section titled “Common tasks”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-03Due: 2026-12-03Build 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:052026-11-30Read text that might not be a date:
set when to nullset when to mash.date.parse("next tuesday-ish")error printline "Couldn't read that date" set when to mash.date.today()endprintline when.format("H:i")Couldn't read that date00:00Find 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"endWatch out for
Section titled “Watch out for”diffInDaysand its relatives are signed.a.diffInDays(b)is positive whenbis later thanaand negative when it’s earlier. Passtrueas a second argument for the plain distance,a.diffInDays(b, true). The answer can have a fraction (4.5hours).- Month ends.
addMonth()from 31 January lands in March.addMonthNoOverflow()stops at the end of February. - Plain
mash.date.parseof a date with no time is midnight. Compare days withisSameDay, not==. - The rounding flags (
mash.date.round,floorandceil) are numbers that some date methods accept. You won’t need them often.
See also
Section titled “See also”Talking to the outside world, Values and types for how dates copy, and the Date type.
Create and process date objects
Properties
Section titled “Properties”| Name | Type | Description |
|---|---|---|
ceil | ||
floor | ||
round |
Methods
Section titled “Methods”create
Section titled “create”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.
tomorrow
Section titled “tomorrow”date.tomorrow() → Date
Get the start of tomorrow.
yesterday
Section titled “yesterday”date.yesterday() → Date
Get the start of yesterday.