Create a segment with a relativ date 'now'

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:

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

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

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.

1 Like

yip that is correct

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.

yes - I just learned that too :slight_smile:

Would be a great feature to have…

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. :rocket:

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.

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?

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.

1 Like

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?

1 Like

@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 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

Great question. I will test it.

1 Like

@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)