Comparing two dates

I am attempting to compare two dates and thought this would be fairly straightforward. I’m not finding that to be the case. I set two variables: one to a random date and the other to now. I converted everything to seconds and figured out how to make the variables numeric. However, when I try to simply subtract one from the other, the result is a text string. I would appreciate any suggestions as to what I’m doing wrong.

Testing Dates.json (5.6 KB)
image


image
image
image

Use the operator from make, not the - on your keyboard.

image

You can type it like this: {{-}}

L

2 Likes

Hi @Todd_Cook

Please use the below formula:

Time diff between days
{{round((Date1 - Date2) / (1000 * 60 * 60 * 24))}}

Time diff between Minutes
{{round((Date1 - Date2) / 1000 / 60)}}

Ensure you apply parse function if the date is not of date datatype.

Regards,
Msquare Automation - Gold Partner of Make

Book a Free Consultation | Connect Live

Explore our YouTube Channel for valuable insights and updates!

2 Likes

1.

Firstly, to compare the difference between then and now,

You need to subtract the past date from the current date. Currently you are doing this the opposite way, and you are not using the built-in minus operator.

Screenshot_20240719_155852

2.

If you want to compare the number of days between the two dates,

Then you need to divide the result by 86400 (seconds in a day).

You can use the floor function to reduce it further to whole days.

Screenshot_20240719_155706

3.

Lastly, you do not need formatNumber since both results in a numeric output.

You also do not need parseDate on the {{now}} variable, since it’s already a Date type variable.

Screenshot_20240719_160447

Output

Screenshot_20240719_160258

Module Export

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the JSON code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the canvas.

  3. Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.

Click to Expand Module Export Code

JSON - Copy and Paste this directly in the scenario editor

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 10,
                    "module": "util:SetVariables",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "variables": [
                            {
                                "name": "xfrDate",
                                "value": "{{formatDate(parseDate(\"3/1/2024\"); \" X\")}}"
                            },
                            {
                                "name": "Current",
                                "value": "{{formatDate(now; \"X\")}}"
                            }
                        ],
                        "scope": "roundtrip"
                    },
                    "metadata": {
                        "designer": {
                            "x": 300,
                            "y": 150
                        },
                        "restore": {
                            "expect": {
                                "variables": {
                                    "items": [
                                        null,
                                        null
                                    ]
                                },
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "variables",
                                "type": "array",
                                "label": "Variables",
                                "spec": [
                                    {
                                        "name": "name",
                                        "label": "Variable name",
                                        "type": "text",
                                        "required": true
                                    },
                                    {
                                        "name": "value",
                                        "label": "Variable value",
                                        "type": "any"
                                    }
                                ]
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            }
                        ],
                        "interface": [
                            {
                                "name": "xfrDate",
                                "label": "xfrDate",
                                "type": "any"
                            },
                            {
                                "name": "Current",
                                "label": "Current",
                                "type": "any"
                            }
                        ]
                    }
                },
                {
                    "id": 11,
                    "module": "util:SetVariables",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "variables": [
                            {
                                "name": "SecondsDiff",
                                "value": "{{10.Current - 10.xfrDate}}"
                            },
                            {
                                "name": "DaysDiff",
                                "value": "{{floor((10.Current - 10.xfrDate) / 86400)}}"
                            }
                        ],
                        "scope": "roundtrip"
                    },
                    "metadata": {
                        "designer": {
                            "x": 600,
                            "y": 150
                        },
                        "restore": {
                            "expect": {
                                "variables": {
                                    "items": [
                                        null,
                                        null
                                    ]
                                },
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "variables",
                                "type": "array",
                                "label": "Variables",
                                "spec": [
                                    {
                                        "name": "name",
                                        "label": "Variable name",
                                        "type": "text",
                                        "required": true
                                    },
                                    {
                                        "name": "value",
                                        "label": "Variable value",
                                        "type": "any"
                                    }
                                ]
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            }
                        ],
                        "interface": [
                            {
                                "name": "SecondsDiff",
                                "label": "SecondsDiff",
                                "type": "any"
                            },
                            {
                                "name": "DaysDiff",
                                "label": "DaysDiff",
                                "type": "any"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

1 Like

Thanks very much. I was not aware there was a difference between the minus sign and the in-program function.

Thanks very much, @Msquare_Automation

1 Like

Thanks very much, Sam. The biggest part of my issue was the minus vs the built-in subtraction function. Once I changed that, it began to make more sense. Ultimately, I ended up with the below. I can now incorporate these learnings into my active scenarios. Thanks again for a clear, concise explanation of concepts.


2 Likes

No problem, glad I could help!

1. If anyone has a new question in the future, please start a new thread. This makes it easier for others with the same problem to search for the answers to specific questions, and you are more likely to receive help since newer questions are monitored closely.

2. The Make Community guidelines encourages users to try to mark helpful replies as solutions to help keep the Community organized.

This marks the topic as solved, so that:

  • others can save time when catching up with the latest activity here, and
  • allows others to quickly jump to the solution if they come across the same problem

To do this, simply click the checkbox at the bottom of the post that answers your question:
Screenshot_2023-10-04_161049

3. Don’t forget to like and bookmark this topic so you can get back to it easily in future!

4. Do join the unofficial Make Discord server for live chat and video assistance

Here are some useful links and guides you can use to learn more on how to use the Make platform, apps, and app modules. I found these useful when I was learning Make, and hope they might benefit you too —

General

Help Center Basics

Articles & Videos

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

1 Like

Glad to know that the solution provided was helpful.

Regards,
Msquare Automation - Gold Partner of Make

Book a Free Consultation | Connect Live

Explore our YouTube Channel for valuable insights and updates!