# Campaign rules based on date comparison

**URL:** <https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212>\
**Category:** Product Support\
**Created:** [February 6, 2018, 11:58am UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212 "2018-02-06T11:58:00Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlebedev](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dlebedev](https://forum.mautic.org/u/dlebedev)\
**Post date:** [February 6, 2018, 11:58am UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212/1 "2018-02-06T11:58:00Z")

</div>

Hi guys,

I am creating a campaign in Mautic now and I was wondering if someone knows how to solve my problem.

I have a date field that represents the date of user’s last transaction. In my campaign I want to set up a rule: if the transaction happened more than 7 days ago, the user should get a tag. Once the date is less than 7 days ago, the tag should be removed.

Any idea on how to solve that?

Thanks!

---

<div class="post-metadata">

**Author:** ![petertl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/petertl/32/511_2.png) [@petertl](https://forum.mautic.org/u/petertl)\
**Post date:** [February 7, 2018, 5:42am UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212/2 "2018-02-07T05:42:03Z")

</div>

You will have to create a segment for that and base a campaign on it. The segment filter will have to be:

`[Last Transaction Date] greater than or equal "today-7"`

Just don’t pick a date but input the `today-7` manually into the date input field of the segment.

After that, create a campaign which assigns the contact tag. Whenever a contact reaches a transaction data which is 7 days (or more) in the past, it will go into the segment and into the campaign.

---

<div class="post-metadata">

**Author:** ![petertl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/petertl/32/511_2.png) [@petertl](https://forum.mautic.org/u/petertl)\
**Post date:** [February 7, 2018, 6:01am UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212/3 "2018-02-07T06:01:01Z")

</div>

Sorry, of course it has to be `[Last Transaction Date] less than or equal "today-7"` (not **greater** )

---

<div class="post-metadata">

**Author:** ![dlebedev](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dlebedev](https://forum.mautic.org/u/dlebedev)\
**Post date:** [February 7, 2018, 5:13pm UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212/4 "2018-02-07T17:13:58Z")

</div>

Thanks Peter!

Do you think this will create a sliding window of dates?

What I mean: if today I setup the "greater than or equal “today-1”, (and it’s the 8th of February today), the segment will be updated with those people who’s dates are 7th and 8th, but will it be updated tomorrow with people with newer dates automatically?

Thank you once again,

Cheers

---

<div class="post-metadata">

**Author:** ![petertl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/petertl/32/511_2.png) [@petertl](https://forum.mautic.org/u/petertl)\
**Post date:** [February 8, 2018, 2:17am UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212/5 "2018-02-08T02:17:35Z")

</div>

Yes DL, this is exactly what will happen. The “today” is replaced with the current date when the segment is updated. So tomorrow it will have another date period than the day after tomorrow.

---

<div class="post-metadata">

**Author:** ![dlebedev](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dlebedev](https://forum.mautic.org/u/dlebedev)\
**Post date:** [February 9, 2018, 12:06pm UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212/6 "2018-02-09T12:06:20Z")

</div>

This works! Thanks Peter!

---

<div class="post-metadata">

**Author:** ![alberto](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alberto/32/276_2.png) [@alberto](https://forum.mautic.org/u/alberto)\
**Post date:** [February 14, 2018, 12:41am UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212/7 "2018-02-14T00:41:49Z")

</div>

Great discussion as I have a related question. Is it also possible to get the current year for comparison with a custom year field (not an actual Mautic date field). So for example, I want to create a segment where [CustomYearField] is equal to the current year (without having to change the segment every year).

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![petertl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/petertl/32/511_2.png) [@petertl](https://forum.mautic.org/u/petertl)\
**Post date:** [February 14, 2018, 8:04am UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212/8 "2018-02-14T08:04:55Z")

</div>

Alberto, is there any way to convert your custom field to a date(time) field? It yes, two simple segment filter ( **greater than 1.1.2018** and **less than 31.12.2018** ) should do it.

But: you will have to change your segment manually which should not be too much effort once a year. 😉

Otherwise, currently there is no Mautic standard functionality to accomplish that.

---

<div class="post-metadata">

**Author:** ![alberto](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alberto/32/276_2.png) [@alberto](https://forum.mautic.org/u/alberto)\
**Post date:** [February 15, 2018, 1:09am UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212/9 "2018-02-15T01:09:05Z")

</div>

Hi Peter, thank you for the quick reply. Sure, changing the segment on a yearly basis isn’t a big deal. I was just curious what is possible as I wasn’t aware you could use ‘today’ within fields. Is there documentation somewhere as to what else can be used in fields for comparison when it comes to dates?

---

<div class="post-metadata">

**Author:** ![petertl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/petertl/32/511_2.png) [@petertl](https://forum.mautic.org/u/petertl)\
**Post date:** [February 15, 2018, 5:16am UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212/10 "2018-02-15T05:16:05Z")

</div>

I haven’t found any documentation on this. I think **today** , **yesterday** and **tomorrow** work. The rest can be accomplished with **today+/-number**. I think this is nothing Mautic brings with it per se but the software platform it is built with.

---

<div class="post-metadata">

**Author:** ![alberto](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alberto/32/276_2.png) [@alberto](https://forum.mautic.org/u/alberto)\
**Post date:** [February 16, 2018, 2:55am UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212/11 "2018-02-16T02:55:38Z")

</div>

Got it, thanks!

---

<div class="post-metadata">

**Author:** ![ojacquet](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ojacquet/32/228_2.png) [@ojacquet](https://forum.mautic.org/u/ojacquet)\
**Post date:** [July 5, 2018, 10:12am UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212/12 "2018-07-05T10:12:54Z")

</div>

\> I think today, yesterday and tomorrow work

Indeed, they work.

\> The rest can be accomplished with today+/-number.

That doesn’t work for me.

---

<div class="post-metadata">

**Author:** ![dlebedev](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dlebedev](https://forum.mautic.org/u/dlebedev)\
**Post date:** [July 6, 2018, 9:22am UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212/13 "2018-07-06T09:22:59Z")

</div>

What actually works for me is “-X days” and “+X days” on a date field.  
You can take a register date field and use “greater than or equal” “-7 days” to it, which will include all signups from 7 days ago till today.

---

<div class="post-metadata">

**Author:** ![Roblopes](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@Roblopes](https://forum.mautic.org/u/Roblopes)\
**Post date:** [August 11, 2018, 5:06pm UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212/14 "2018-08-11T17:06:20Z")

</div>

Hi @DL, thanks for the tip. Today-X wasn’t working for me. using “-X days” worked. Thanks a lot!  
Rob

---

<div class="post-metadata">

**Author:** ![amars](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/amars/32/580_2.png) [@amars](https://forum.mautic.org/u/amars)\
**Post date:** [November 15, 2021, 9:41am UTC](https://forum.mautic.org/t/campaign-rules-based-on-date-comparison/10212/15 "2021-11-15T09:41:00Z")

</div>

Hello @petertl  
I actually want to send a series of reminder emails to our users before his/her subscription ends.  
Is there any solution for this?
