Skip to main content

Analysis limitations on date fields

Are you tracking a property where data type = date?

Sample group property date field synced from Salesforce to Amplitude

There are a few ways you can filter on date fields in Amplitude today. You can build a cohort or chart segment using the following operator conditions

  • = specific date
  • ≠ specific date

  • ∋ portion of the date string

  • ∌ portion of the date string

  • > or ≥ specific date (all days after that single point in time)

  • < or ≤ specific date (all days before that single point in time)

However, these are all relatively static filters. If you need to set a dynamic filter on a date field relative to today, keep reading below.

 

Use cases to expand analysis and targeting on date fields relative to TODAY()

But there’s even more capability that you can unlock by building a derived property that identifies how many days until a future date will happen, with respect to today’s relative date. There are a few use cases where this concept of “days until x date from today’s relative date” becomes a critical signal in analyses and cohorts…

  • Use case a: Exclude users and accounts from upsell targeting if they have a future contract start date after an opportunity has been closed won.

    • Oftentimes when sales reps close a deal with a new customer, the customer will ask for a future contract start date, starting next month when they have the resources and bandwidth to begin the project with the vendor. Growth Marketing teams need to be able to suppress these “future customers” with a future contract start date from their digital programs in order to avoid double-upselling product features that have already been purchased. So within the target cohort, it’s important to specify the target user group does not have a contract start date in the next n days from now. 

  • Use case b: Exclude users and accounts from digital nurture programs that are approaching a contract end date.

    • For recurring marketing campaigns, it’s a strategic tactic to exclude users associated with contracts that are approaching a contract end date within the next n days. 

  • Use case c: Target users and accounts to collect feedback n days prior to the contract expiration date.

    • Contrary to use case b, there might be an intentional program seeking feedback only from users and accounts that are not renewing their contracts. In this case, it’s important to have this “days until x date” field readily available for cohort targeting.

There are additional scenarios to target or analyze users “n days since x date” to narrow down the audience to users and accounts who are at least n days past their contract start date. 

  • Use case d: Target users within accounts that are at least n days past their contract start date.
    • It’s important to consider which stage in the account lifecycle is ready to receive specific content. Whether you want to set a tenure maturity level requirement before sending specific content to an account, or if you just wish to avoid overlapping programs with content sent during the onboarding and activation stages, a property that indicates “days since x date” is critical to leverage. 

 

At Amplitude, the Growth Marketing team factors this “days until x date” criteria in many of the cohorts that target active paid contracts. In order to target users on an active Salesforce contract who are at least n days into their contract AND more than n days out from their contract end date, we need to extract 2 new derived properties from existing group properties.

 

Extract this data and stamp it onto a newly derived property with retroactive data 

In order to set up this “date relative to today” field in Amplitude Data, navigate to the derived properties tab and create a new derived property.

⬇️ Below is the logic we used for this specific derived property setup.

How to interpret this logic:

  • First convert the date field with DATE_TO_LONG function. If you’re referencing a datetime field, use the TIME_TO_LONG function.
  • Next subtract the current date with MINUS () and TODAY () functions
  • Then divide by 86,400,000 milliseconds to convert the output into days
  • The final values will yield negative for past dates and positive for future dates
  • Test out your new derived property with the preview outcome feature
  • Finally, plug in your new derived property into your cohort. Our original example is the following:  
    • at least 90 days into the contract:  days since contract initial start date ≤  -90.0
    • more than 30 days out from their contract end date: days until future subscription end > 30.0
CEIL(
DIVIDE(
MINUS(
DATE_TO_LONG(
<<insert original date property here>>
),
TODAY()
),
86400000
)
)

  YO7Ves6snQHmtT9VRcaT_rA8OzTYH87xW6aZWaFTkjUSnZaoYtX9KLCZa4miJWAaNhoV-opUlDOKNev-K0f98h2RGPi6mffK18Q6w64w_f6Uu6yLez3VUSb6qlyjUoB7E0Fu8E9yAeI3Ux93NPH60NY

 

 

Build analyses and cohorts with newly derived properties

Now that you’ve configured a newly derived property, you can build out advanced logic that is dynamic, relative to today’s date. Make sure to set a clear property definition for others to benefit from using this data as well. 

This newly derived property will always be prefixed with fx to easily differentiate it from other properties. 

 

This new data enables you to dynamically target the right audience based on days since key dates in a contract happened, and days until key dates in a contract occur. 

 

Comment below if you have any questions.

Hey @JennRu ,

really nice example.
For which plan types is this available?


Hi @Micha derived properties are available to growth and enterprise customers who purchase the govern add-on


NOTE: The above formulas for these derived properties reference

TODAY()

which is a function related to the time the query is run, not the time the event is ingested. 

Therefore when I plug this derived property into a cohort, I need to adjust my lookback window to the last 1 day

If I use the default last 30 days lookback window, this will unintentionally be overly inclusive to orgs/accounts/users that met this criteria 30 days ago. 

E.g. Account X has a subscription end date = June 1, 2024

Let’s say today is May 30, 2024. 

30 days ago, Account X would qualify for the condition below: days until future subscription end > 30.0

However we don’t want to qualify Account X TODAY() on May 30, 2024 when we’re building this cohort. So we must reduce the lookback window to last 1 day.

This type of derived property is based on TODAY() which is a function related to the query run time. This means any time-sensitive targeting, such as this example to remove accounts with an upcoming subscription_end date in the next 30 days, should have a lookback window of last 1 day to guarantee most accurate targeting, with respect to the current date.

 

Alternatively, if you are including a further lookback window for any additional reasons, you can include and AND condition to remove accounts that meet the following condition: 

did not have  days until future subscription end date ≤ 30

This guarantees at any point if an account has an upcoming subscription_end date in the next 30 days, they will be removed from the cohort.

 

If you need to include a further lookback window in the first condition, be sure to have a secondary negative condition to remove accounts with an upcoming subscription_end date ≤ 30 days from TODAY().

 


Alternatively, you can explore setting up your derived property using server_upload_time instead which is the time an event is ingested into Amplitude. So if you ever need to pair this derived property at the time an event occurred, you can use the following formula for your derived property build:

CEIL(
DIVIDE(
MINUS(
DATE_TO_LONG(
<<insert original date property here>>
),
PROPERTY('server_upload_time', 'amplitude_user')
),
86400000
)
)

Note: Contingent on your use case, you might need to switch the order of the subtraction if you want to calculate the days since a past date has occurred, as opposed to the days until a future date will occur.


Reply