Using date operations

How to use date operations in Plytix formulas, with real examples of when you'd use each one

Date operations let you add to, subtract from, or reformat a date attribute's value within a formula, without changing the date actually stored in Plytix. This article covers all seven date operations, plus common use cases combining them.

ADD_DAYS

Adds a number of days to a date.

Syntax:

ADD_DAYS(date, days)
  • date: the date to add days to.
  • days: the number of days you want to add.

Compatible attribute types: Date attributes.

Example:

ADD_DAYS("2020-03-30", 2)

Result: 2020-04-01

Formula in use:

ADD_DAYS($ATT.SALE_EXPIRY_DATE, 15)

This adds 15 days to the date stored in SALE_EXPIRY_DATE. For example, a starting date of January 1, 2020 results in January 16, 2020.

ADD_MONTHS

Adds a number of months to a date.

Syntax:

ADD_MONTHS(date, months)
  • date: the date to add months to.
  • months: the number of months you want to add.

Compatible attribute types: Date attributes.

Example:

ADD_MONTHS("2020-03-30", 2)

Result: 2020-05-30

Formula in use:

ADD_MONTHS($ATT.SALE_EXPIRY_DATE, 2)

ADD_YEARS

Adds a number of years to a date.

Syntax:

ADD_YEARS(date, years)
  • date: the date to add years to.
  • years: the number of years you want to add.

Compatible attribute types: Date attributes.

Example:

ADD_YEARS("2020-03-30", 5)

Result: 2025-03-30

Formula in use:

ADD_YEARS($ATT.SALE_EXPIRY_DATE, 1)

SUB_DAYS

Subtracts a number of days from a date.

Syntax:

SUB_DAYS(date, days)
  • date: the date to subtract days from.
  • days: the number of days you want to subtract.

Compatible attribute types: Date attributes.

Example:

SUB_DAYS($ATT.CREATED, 2)

This subtracts 2 days from the date stored in CREATED.

SUB_MONTHS

Subtracts a number of months from a date.

Syntax:

SUB_MONTHS(date, months)
  • date: the date to subtract months from.
  • months: the number of months you want to subtract.

Compatible attribute types: Date attributes.

Example:

SUB_MONTHS($ATT.CREATED, 2)

This subtracts 2 months from the date stored in CREATED.

SUB_YEARS

Subtracts a number of years from a date.

Syntax:

SUB_YEARS(date, years)
  • date: the date to subtract years from.
  • years: the number of years you want to subtract.

Compatible attribute types: Date attributes.

Example:

SUB_YEARS($ATT.CREATED, 2)

This subtracts 2 years from the date stored in CREATED.

DATE_FORMAT

Changes how a date displays, using format tokens (for example, %d for day, %b for abbreviated month name, %Y for a 4-digit year).

Syntax:

DATE_FORMAT(date, format)
  • date: the date to be formatted.
  • format: the new format of the date, built from format tokens.

Example:

$ATT.DATE = 2020-03-22

DATE_FORMAT($ATT.DATE, "%d-%b-%Y")

Result: 22-Mar-2020

Common Use Cases for Date Operations

Setting a promotion or sale end date

Instead of manually calculating and entering an end date for every sale, calculate it automatically from a start date:

ADD_DAYS($ATT.SALE_START_DATE, 14)

This keeps your sale-end date accurate even if the start date changes.

Displaying dates in the format your audience expects

Different regions and platforms expect different date formats. Use DATE_FORMAT to reformat the same underlying date differently for different Channels or Brand Portals, without maintaining separate date attributes:

DATE_FORMAT($ATT.RELEASE_DATE, "%m/%d/%Y")

Calculating a next review or restock date

If you track when a product was last reviewed or restocked, calculate the next due date automatically instead of tracking it manually:

ADD_MONTHS($ATT.LAST_RESTOCKED, 3)

Building a rolling "recently added" window

Combine SUB_DAYS with a comparison operation (see Logical operations) to check whether a product was created within a certain window, useful for flagging new arrivals without a manual badge:

SUB_DAYS(TODAY(), 30)

Compare a product's creation date against this rolling threshold to determine whether it still counts as "new."

Calculating a warranty or subscription expiration date

Add the warranty or subscription length to a purchase or activation date to calculate when it expires, keeping the expiration always accurate without manual upkeep:

ADD_YEARS($ATT.PURCHASE_DATE, 2)

 These date operations are especially useful combined with logical operations like IF, GT, and LT, for example, to automatically flag products as expiring soon, or to hide a promotion once its calculated end date has passed. See Logical operations for more.

Frequently Asked Questions

No. They only affect the formula’s output; your original Date attribute remains unchanged.

Yes. You can combine date operations with logical operators (such as IF, GT, and LT) to create dynamic rules, like flagging products that are new or expiring soon.

Date operations can only be applied to Date attributes.