# Create a segment with a relativ date 'now'

**URL:** <https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499>\
**Category:** Product Support\
**Created:** [May 18, 2021, 7:04am UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499 "2021-05-18T07:04:23Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![adiux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/adiux/32/5793_2.png) [@adiux](https://forum.mautic.org/u/adiux)\
**Post date:** [May 18, 2021, 7:04am UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499/1 "2021-05-18T07:04:23Z")

</div>

**Your software**  
My Mautic version is: 3.3.0  
My PHP version is: 7.4  
My Database type and version is: Mysql

**Your problem**  
My problem is:  
I like to create a segment with all the contacts where the contacts field value is bigger than a certain date **and time**. I know I can use the relative format `today`. But can I also use a time. Something similar to `now`?

E.g  
Give me all contacts where the field `date` (e.g. 2021-05-18T11:30:00) is \>= now

I use a custom field with a datetime type for that.

Related documentation:

> **[Manage segments](https://docs.mautic.org/en/contacts/manage-segments#segment-filters)**
>
> . Lead lists were renamed to segments in Mautic 1.4.0.Segments provide ways to easily organize your contacts. These segments can be configured from a variety of fields.When viewing all segments you will notice the column on the right which shows the...

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [May 18, 2021, 7:51am UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499/2 "2021-05-18T07:51:58Z")

</div>

Hi @adiux you might try using the field date is greater than or equal to “today”

---

<div class="post-metadata">

**Author:** ![adiux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/adiux/32/5793_2.png) [@adiux](https://forum.mautic.org/u/adiux)\
**Post date:** [May 19, 2021, 7:31am UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499/3 "2021-05-19T07:31:00Z")

</div>

I think this will only consider the date, but not the **time**?

---

<div class="post-metadata">

**Author:** ![tpapaj](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/tpapaj/32/3198_2.png) [@tpapaj](https://forum.mautic.org/u/tpapaj)\
**Post date:** [May 19, 2021, 7:47am UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499/4 "2021-05-19T07:47:13Z")

</div>

Did you try to use the word “now”? It’s not in documentation but I am using it in campaigns and it works, I did not try to use it in segments however. As you discovered, “today” does not work on time.

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [May 19, 2021, 1:56pm UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499/5 "2021-05-19T13:56:45Z")

</div>

yip that is correct

---

<div class="post-metadata">

**Author:** ![alexhammer](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexhammer/32/14525_2.png) [@alexhammer](https://forum.mautic.org/u/alexhammer)\
**Post date:** [May 19, 2021, 2:10pm UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499/6 "2021-05-19T14:10:07Z")

</div>

I am playing around with the same feature at the moment.  
If you use “now” as the date filter it works for the moment of saving. Then this exact time is saved as the filter value.

---

<div class="post-metadata">

**Author:** ![adiux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/adiux/32/5793_2.png) [@adiux](https://forum.mautic.org/u/adiux)\
**Post date:** [May 19, 2021, 2:23pm UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499/7 "2021-05-19T14:23:17Z")

</div>

yes - I just learned that too 🙂

Would be a great feature to have…

---

<div class="post-metadata">

**Author:** ![alexhammer](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexhammer/32/14525_2.png) [@alexhammer](https://forum.mautic.org/u/alexhammer)\
**Post date:** [May 20, 2021, 5:26am UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499/8 "2021-05-20T05:26:36Z")

</div>

Yes. The other possibility which would solve that would be:

In any action you can schedule the action for a specific date. Right now this takes only a date/time stamp as input. But if we make this function accept a custom field (date/time) as input it would give us a lot of freedom regarding timed campaigns. 🚀

---

<div class="post-metadata">

**Author:** ![tpapaj](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/tpapaj/32/3198_2.png) [@tpapaj](https://forum.mautic.org/u/tpapaj)\
**Post date:** [May 20, 2021, 7:30am UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499/9 "2021-05-20T07:30:08Z")

</div>

Interesting, I checked and you are right, in segments the “now” is replaced by the current time after saving. It’s weird because it means that field filter in campaign and filter in segments parse “now” in different ways, I wish the segment filter worked like the field filter in campaigns.

---

<div class="post-metadata">

**Author:** ![alexhammer](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexhammer/32/14525_2.png) [@alexhammer](https://forum.mautic.org/u/alexhammer)\
**Post date:** [June 8, 2021, 9:29am UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499/10 "2021-06-08T09:29:17Z")

</div>

Do you get it to work within a campaign?  
If I use a custom field value with a datetime field i.e. 2021-06-08 12:28:00 equals “now”.  
It doesn’t meet the conditions and fails.

Does it work for you?

---

<div class="post-metadata">

**Author:** ![tpapaj](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/tpapaj/32/3198_2.png) [@tpapaj](https://forum.mautic.org/u/tpapaj)\
**Post date:** [June 9, 2021, 9:01am UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499/11 "2021-06-09T09:01:52Z")

</div>

I wouldn’t use “equals” with that because the campaign would have to be triggered in that exact moment, so “now” equlas 2021-06-08 12:28:00 means you have only one second window in which the condition is true.  
I would use “less than” or “greater than”.

I am using it in following example: In my contacts I have a datetime field(let’s call this ActionDeadline), after that datetime passes I need to do some action on the contact. They belong to a segment. I have a campaign on that segment and I have a Condition which says “ActionDeadline - greater than - now”. If it’s false I do not do anything and I restart the campaign(or wait and then restart to reduce amount of campaign processing). If it’s true I do some actions on the contact instead.

I am using Mautic 3.2.4 currenty with this.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [June 9, 2021, 11:00am UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499/12 "2021-06-09T11:00:22Z")

</div>

I’m not sure if you guys want this but I have the following example:

I update the abandoned cart custom field for the contact with current timestamp.  
So you come to the site, and enter the cart payment page, you get updated with abandonedcarttime custom filed will have that moment when it happened. Let’s say “2021.06.09. 12:00.”

Now I want to start a campaign for anyone who has an abandoned cart. This campaign wil be 48 hours long.

My Segment will look like: “abandonedcarttime \> -2 days”

So anyone who has visited the cart will be in the segment for 2 days. On day 3 they will leave the segment (and the campaign as well.) Because abandonedcarttime will be larget then -2 days. In fact it will be smaller than -2 days, since it will be -3 days. (Which is smaller.)

Is this what you are looking for?

---

<div class="post-metadata">

**Author:** ![alexhammer](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexhammer/32/14525_2.png) [@alexhammer](https://forum.mautic.org/u/alexhammer)\
**Post date:** [June 9, 2021, 12:27pm UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499/13 "2021-06-09T12:27:27Z")

</div>

@joeyk This is nice. Is it working with the timestamp?  
when your leads comes in the segment at “2021.06.09. 12:00.” is the lead leaving the segment on 2021.06.11 12:00 or at 00:00?

@tpapaj With the Draft PR [#9784](https://github.com/mautic/mautic/pull/9784) the thing with less than or greater than works really fine! Thank you for that hint!  
To fill it with leads every minute I update only this particular segment with a cronjob i.e  
php bin/console m:s:u --list-id=1

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [June 9, 2021, 6:32pm UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499/14 "2021-06-09T18:32:45Z")

</div>

Great question. I will test it.

---

<div class="post-metadata">

**Author:** ![alexhammer](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexhammer/32/14525_2.png) [@alexhammer](https://forum.mautic.org/u/alexhammer)\
**Post date:** [June 10, 2021, 8:00am UTC](https://forum.mautic.org/t/create-a-segment-with-a-relativ-date-now/19499/15 "2021-06-10T08:00:23Z")

</div>

@adiux exactly what you asked for when you started the thread can be done with the PR #9784 what I mentioned above.  
I am using it in one of our projects in production already and it works great.

datetime customfield - smaller than - today

this works nicely. next to that I update this particular segment every minute via cron (like above)
