When you need to compare two events by date, checking their exact timestamps manually is not the most practical approach. It is time-consuming and not scalable, especially when you want to use the logic in segmentations or campaign targeting.
In this article, we’ll show you how to verify whether two different events happened on the same calendar day, even if they occurred at different times.
Example use case
Let's say you want to see how many customers made their first purchase on the same day they clicked the first email campaign they received.
Step-by-step guide
Navigate to
Analytics > Segmentationsand click on theNew segmentationbutton in the top-right corner.
The segmentation builder opens with a customer filter. Keep the filter in matching mode so that the resulting segment contains customers who satisfy the configured funnel conditions.In the first funnel step, select the
campaignevent where the timestamp equals attribute.Click "Select an attribute," then choose "Add new aggregate" in the Aggregates section.
Create an aggregate that returns the timestamp of the first
campaignevent matching the selected conditions. In this case, the conditions will beaction_type = emailandstatus = clicked.
Configure the aggregate as follows:
1. Select first as the aggregation method.
2. Select thecampaignevent.
3. Select thetimestampattribute.
4. Add the following event filters:
-action_typeequalsemail
-statusequalsclicked
5. Name the aggregate.
6. Click Apply to save the expression.If your use case requires a different campaign interaction, adjust the event filters. For example, you might use a different
action_typeorstatusvalue.The aggregate returns an exact timestamp, including the time of day. Comparing that exact value to a purchase timestamp would only match if both events occurred at exactly the same time. Because of that, you'll need to create an event expression that converts the campaign timestamp to the start of its day (00:00:00.000).
To create the expression:
1. Click Refine more below the campaign filter.
2. Select Event expression.
3. Click Add new event expression.
4. Select the campaigntimestampattribute.
5. Enter the following formula using the timestamp of the campaign:floor(timestamp / 86400) * 864006. Give the expression a descriptive name.
7. Click Apply to save the expression.Note: this event expression takes a timestamp such as
17 Apr 2026, 14:07:44.631and transforms it to17 Apr 2026, 00:00:00. Be aware that the expression does not modify the original event or its stored timestamp. It only changes the value used by the segmentation filter.Make sure the event expression from the previous step equals an attribute. Select the attribute - "Add new aggregate".
Create an aggregate that returns the timestamp of the customer’s first purchase. This will be used to check whether the events happened on the same day.
Configure the aggregate as follows:
1. Select first as the aggregation method.
2. Select thepurchaseevent.
3. Select a newevent expressionas an attribute.The campaign and purchase values must be transformed in the same way. To make sure you compare a rounded-down timestamp with another rounded-down timestamp, proceed with creating an event expression, in this case, for the
purchaseevent. Use the formula from step 5, but this time, reference the purchase timestamp, not the campaign timestamp. In the expression editor, the attribute path should therefore point topurchase > timestamp.Apply the changes and preview the segment.
Using the same logic to compare if the events are within an hour
If you want to take this logic a step further and match only profiles where the two events happened within the same hour, you can slightly adjust the rounding down expression, like this:
floor(timestamp / 3600) * 3600Applications
This approach can be applied in many different scenarios where you need to compare two events by date without relying on exact timestamps.
If needed, the same logic can also be adapted to compare an event timestamp with a timestamp stored in a customer attribute.