Skip to content
Learn › Clean and shape data: open the docs menu

Work with dates and financial years

Mammoth's date functions shift dates, pull out parts such as the month or weekday, add a financial year and measure the time between two dates. Open them from the Describe your transformation bar (or a + button in the Pipeline panel) › Date, Numeric & Text. Each one is a pipeline task that runs again every time the pipeline refreshes. Only Date columns appear in the date dropdowns: convert text dates first with Convert Column Type (Convert text to dates and numbers).

Add or subtract days, months or years from a date

Add / Subtract Date Values moves a date forward or back, for deadlines, expiry dates or lining up dates across periods.

Add / Subtract Date Values panel adding 30 days to event_date, with the result placed in a new column New_event_date
  1. In Select column, choose the date column.
  2. In Select behaviour, choose Add or Subtract.
  3. Enter an amount in one or more of the duration fields: Years, Months, Weeks, Days, Hours, Minutes or Seconds. Fields left at 0 are ignored.
  4. Optional: click Add Condition to shift only the rows that meet a condition.
  5. In Place in, choose New Column and type a name, or choose Existing Column and pick the column to overwrite.
  6. Optional: click the calendar icon next to the result column options to pick the date format. The formats come in Universal, US and UK groups.
  7. Click Apply.

Example: to set a review date 30 days after a contract starts, select contract_start, choose Add, enter 30 in Days and name the new column review_due.

Get the year, month, weekday or time from a date

Extract Date Part pulls one part out of a date, such as the year, month name, week number or hour, and writes it to a new column.

  1. In Select column, choose the date column.
  2. In Select date part, choose the part you want. Each part shows an icon for its result type (number, text or date).
  3. Name the result column and click Apply.

The pipeline card names the result type in brackets, for example "Month name (text)".

Date partResult typeReturns
YearNumberFor example 2024
QuarterNumber1, 2, 3 or 4
MonthNumber1–12
Month nameTextFor example "March"
Week of the yearNumber0–53 (weeks start on Sunday; days before the first Sunday are week 0)
WeekdayTextFor example "Monday"
DayNumber1–31
Day of yearNumber1–366
HourNumber0–23
MinutesNumber0–59
SecondsNumber0–59
MillisecondNumber0–999
Time without millisecondsTextFor example "14:40:45"
Time with millisecondsTextFor example "14:40:45.123"
Year & MonthTextFor example "2024 March"
Year & Month NumberTextFor example "2024-03"
Date part without timeDateThe date with its time removed
Date part without timeTextThe same, returned as text

Financial years are not in this list: use Financial Year (Add a financial year column).

Example: to group sales by month, extract Month name from order_date. The new column holds values such as "January" and "February", ready to use as a group in Group, pivot and unpivot.

Calculate the number of days between two dates

Calculate Date Difference measures the time between two dates and returns a number. Each end can be a date column or the current time in UTC.

Calculate Date Difference panel with Start Date and End Date each set to Date Column or Current Time (UTC), a Select Unit dropdown, and a new number column name
  1. In Start Date, select Date Column and choose a column, or select Current Time (UTC). With Current Time (UTC), the column dropdown goes away.
  2. Set End Date the same way.
  3. In Select Unit, choose Years, Months, Weeks, Days, Hours, Minutes or Seconds.
  4. In Place in, choose New Column and type a name, or choose Existing Column to overwrite one.
  5. Click Apply.

Examples:

  • To measure shipping time, set Start Date to order_date, End Date to ship_date, the unit to Days and the name to days_to_ship.
  • To count the days since each customer signed up, set Start Date to signup_date and End Date to Current Time (UTC).

How each unit is counted

The result is End Date minus Start Date. It is negative when the end comes before the start.

UnitHow it countsExample: 2024-12-31 to 2025-01-01
YearsThe difference between the calendar year numbers. Months and days are ignored.1
MonthsThe difference in calendar months (years × 12 plus months). Days are ignored.1
WeeksWhole days divided by 7, rounded toward zero0
DaysWhole days between the two dates1
Hours, Minutes, SecondsWhole days converted to that unit, plus the remaining hours, minutes and seconds24 hours

Years and Months only look at the calendar numbers, so 2024-01-31 to 2024-02-01 counts as 1 month. Use Days when you need an exact span.

Current Time (UTC) is the moment the step runs. A result that uses it changes on every run.

Troubleshooting date functions

SymptomCauseFix
Your date column is missing from the dropdownThe column is stored as text, and only Date columns are listedAdd a Convert Column Type step before this one. See Convert text to dates and numbers.
A month difference looks too largeMonths ignores days, so 31 Jan to 1 Feb is 1 monthUse Days for an exact span
A days-since value changes every dayThe step uses Current Time (UTC), which is the time of each runThis is expected. Use a fixed date column if you need a stable number.
Dates arrive in mixed formats and sort wronglyThe column is text, not DateSee Fix a failing step for the date format fix
Was this page helpful?

Something wrong? support@mammoth.io