Comparing Dates

1
Does anyone have a walk through on how to filter a list by comparing dates?  I have an entity with a Date attribute and I want to check if it is more than x days from that date.  Once I get there I want to use that to filter a list of all the items in that entity to show only those items that greater than x days old.
asked
6 answers
6

Scotty,

A thought:  it sounds like a you come from a programming background.  If so, I would recommend you use Studio Pro until you get started with Mendix.  Once you’ve become familiar with Mendix via Studio Pro, I think you’ll be able to find your way through Studio without any problems.

To your main question, sometimes I find pictures can help.  I tried to recreate what you described and have built 2 ways to get the list you want based on today’s date.  Pictures follow:

Entity I created:

Method 1 – retrieve from database (this would be my preferred method)

Method 2 – create variable and use that to retrieve from entity

 

Hope that helps you get going,

Mike

 

answered
1

You are looking for XPath keywords. See the documentation here: https://docs.mendix.com/refguide/xpath-keywords-and-system-variables

You can do a custom XPath retrieve where you do something like this:

[YourDate <= '[%BeginOfCurrentDay%] - 1 * [%YearLength%]']

Regards,

Ronald

answered
0

In a microflow you could create a DateTime variable for this as a ‘checkdate

For example if you want to check if the date is more then 2 days from the beginning of this month you can create a DateTime variable with the following statement: addDays([%BeginOfCurrentMonth%],2)

Then you can check if your date is more then 2 days from this date by checking something like: $Date > $CheckDate

To filter a list you can do something simular, create an xpath retrieve and use a statement which checks if the Date is bigger then then you checkdate variable.

Hope this helps

answered
0

Let me see if I can pull that off.  I have studied and worked in Python and Powershell and things in Mendix are not readily translating over.  I’m trying to learn, but the methodology and conventions seem so different.

answered
0

Okay, this is making absolutely no sense to me, unfortunately.  And the differences in doing the same thing between Mendix Studion online and Mendix Studio Pro desktop are so vastly different it is confusing to try and apply critical thinking to this and work it out.

 

I simply want to retrieve from the Entity (why its called that I am not sure, it’s a database of sorts) which is a DateTime attribute.  Then, I want to check if that date from the entity is more than 365 days old.  That’s all I want to do.  Then make some other decisions based on that result.

 

I am sorry if this is a basic thing, but It is just not making sense to me.  When I try to retrieve from the database, I can select it, but it gives me absolutely no option to select the DateTime attribute.  When I create an object, so that I can select the database DateTime attribute, The only ‘Type’ available is Set.  I have not option to just read the dang date and set it to a variable.


What am I missing here?

answered
0

Scotty,

combine the suggestions of Maarten and Ronald.

  1. Create a variable DateTime
  2. Set output name to ComparisonDate (or some name you prefer)
  3. Us this to construct the XPath in your XPath retrieve
    [Date <= $ComparisonDate]

 

This allows you to debug the microflow and the outcome of the create variable

 

Additionally, in you comments you mention that you struggle with the difference between Studio & Studio Pro. and using %, $, [

I do advice you take the rapid developer online learning path first: https://learn.mendix.com/link/path/31/Become-a-Rapid-Developer-(Analyst)

And tip; if you are stuck while modeling in Studio Pro; hit F1 that will open the related documentation

answered