Parse Date Error

I am trying to generate a discount rate based on the date that an item is submitted. So if it’s submitted before June 1 of Current year then it should be 50, if it’s submitted between June 1 and June 30 then it’s 25, and after June 30 it’s 0.

I had the function working with the {{now}} variable, but when I replace it with the variable for the submission date it didn’t work.

Function with Now Variable:

{{if(now < parseDate(formatDate(now; "YYYY") + "-06-01"; "YYYY-MM-DD"); 50; if(now <= parseDate(formatDate(now; "YYYY") + "-06-30"; "YYYY-MM-DD"); 25; 0))}}

Function:

{{if(8.DateSubmission < parseDate(formatDate(8.DateSubmission; "YYYY") + "-06-01"; "YYYY-MM-DD"); 50; if(8.DateSubmission <= parseDate(formatDate(8.DateSubmission; "YYYY") + "-06-30"; "YYYY-MM-DD"); 25; 0))}}

Sample Data

[
    {
        "IDSubmission": "CwseMkNCtbvs",
        "NameCompany": "cre8ion Group",
        "NameFirst": "Corey",
        "NameLast": "Test Automation",
        "Email": "Corey@cre8iongroup.com",
        "PhoneNumber": "(989) 430-1981",
        "EmailBilling": "cre8iongroup@gmail.com",
        "Session01Type": "Workshop",
        "Session01Name": "",
        "Session01Location": "",
        "Session01Date": "",
        "Session01Package01": "($1075) - Platinum Package: Projector & screen, four (4) handheld/lavalier microphone, small sound system, and computer audio hookup.",
        "Session01Package02": "",
        "Session01Package03": "",
        "Session01ALACarte": "Two-Way Zoom ($1650)\n75'' TV Screen with stand ($2000)\nPost-it Flip Chart ($200)\nLaptop ($425)",
        "Session01Notes": "I would really like to have a cookie today",
        "Session02": "Yes",
        "Session02Type": "Information Session",
        "Session02Name": "",
        "Session02Location": "",
        "Session02Date": "",
        "Session02Package01": "",
        "Session02Package02": "($375) - Premium Package: 75\" TV with screen, two (2) handheld/lavalier microphone, sound system with mixer, and computer audio hookup.",
        "Session02Package03": "",
        "Session02ALACarte": "Two-Way Zoom ($1650)\n75'' TV Screen with stand ($2000)\nPost-it Flip Chart ($200)\nLaptop ($425)",
        "Session02Notes": "No Notes",
        "Session03": "Yes",
        "Session03Type": "Corporate Reception",
        "Session03Name": "",
        "Session03Location": "",
        "Session03Date": "",
        "Session03Package01": "",
        "Session03Package02": "",
        "Session03Package03": "($6450) Platinum Package: Sound system with mixer, 75\" TV with stand, four (4) handheld/lavalier microphone, 16 RGB Uplights - Static Colors, and computer audio hookup.",
        "Session03ALACarte": "Two-Way Zoom ($1650)\n75'' TV Screen with stand ($2000)\nPost-it Flip Chart ($200)\nLaptop ($425)",
        "Session03Notes": "No Notes",
        "Edit Link": "Edit Submission",
        "DateSubmission": "2024-05-07T12:14:31.000Z",
        "__IMTINDEX__": 1,
        "__IMTLENGTH__": 1
    }
]

1. Parsing DateSubmission into Date Type

Looks like the variable DateSubmission is already in a Make supported date format, but you can still parse it by using

According to the Tokens you can use to format a date variable, you can use YYYY-MM-DDTHH:mm:ss.SSSZ.

e.g.:

{{parseDate(105.DateSubmission; "YYYY-MM-DDTHH:mm:ss.SSSZ")}}

Screenshot_2024-06-12_110613

For more information, see Date Formats in the Help Center.

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 unofficial Make Discord server to chat with other makers!

1 Like

2. Get Middle of Year

You can get the “middle” of the year (30 June at 23:59) by either of these two methods:

{{setSecond(setMinute(setHour(setDate(setMonth(now; 6); 30); 23); 59); 59)}}
{{parseDate("30-06-" + formatDate(now; "YYYY") + " 23:59:59"; "DD-MM-YYYY HH:mm:ss")}}

Output
Screenshot_2024-06-12_110629

samliewrequest private consultation

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

1 Like

3. Check if before July

Combining step 1 and 2, adding a less-than operator in-between:

4. Wrap your if-statement

Output

Screenshot_2024-06-12_110606

samliewrequest private consultation

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

1 Like

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.

View Module Export Code

JSON

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 105,
                    "module": "util:SetVariable2",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "name": "DateSubmission",
                        "scope": "roundtrip",
                        "value": "2024-05-07T12:14:31.000Z"
                    },
                    "metadata": {
                        "designer": {
                            "x": -2030,
                            "y": 291,
                            "name": "Set Date String"
                        },
                        "restore": {
                            "expect": {
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "name",
                                "type": "text",
                                "label": "Variable name",
                                "required": true
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            },
                            {
                                "name": "value",
                                "type": "any",
                                "label": "Variable value"
                            }
                        ],
                        "interface": [
                            {
                                "name": "DateSubmission",
                                "label": "DateSubmission",
                                "type": "any"
                            }
                        ]
                    }
                },
                {
                    "id": 107,
                    "module": "util:SetVariables",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "variables": [
                            {
                                "name": "ParsedDate",
                                "value": "{{parseDate(105.DateSubmission; \"YYYY-MM-DDTHH:mm:ss.SSSZ\")}}"
                            },
                            {
                                "name": "MiddleOfYear",
                                "value": "{{setSecond(setMinute(setHour(setDate(setMonth(now; 6); 30); 23); 59); 59)}}"
                            },
                            {
                                "name": "MiddleOfYearAlt",
                                "value": "{{parseDate(\"30-06-\" + formatDate(now; \"YYYY\") + \" 23:59:59\"; \"DD-MM-YYYY HH:mm:ss\")}}"
                            },
                            {
                                "name": "IsBeforeJuly",
                                "value": "{{parseDate(105.DateSubmission; \"YYYY-MM-DDTHH:mm:ss.SSSZ\") < \"\n\"}}{{parseDate(\"30-06-\" + formatDate(now; \"YYYY\") + \" 23:59:59\"; \"DD-MM-YYYY HH:mm:ss\")}}"
                            },
                            {
                                "name": "DiscountRate",
                                "value": "{{if(parseDate(105.DateSubmission; \"YYYY-MM-DDTHH:mm:ss.SSSZ\") < parseDate(\"30-06-\" + formatDate(now; \"YYYY\") + \" 23:59:59\"; \"DD-MM-YYYY HH:mm:ss\"); 25; 0)}}"
                            }
                        ],
                        "scope": "roundtrip"
                    },
                    "metadata": {
                        "designer": {
                            "x": -1785,
                            "y": 290,
                            "name": "Check if before July"
                        },
                        "restore": {
                            "expect": {
                                "variables": {
                                    "items": [
                                        null,
                                        null,
                                        null,
                                        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": "ParsedDate",
                                "label": "ParsedDate",
                                "type": "any"
                            },
                            {
                                "name": "MiddleOfYear",
                                "label": "MiddleOfYear",
                                "type": "any"
                            },
                            {
                                "name": "MiddleOfYearAlt",
                                "label": "MiddleOfYearAlt",
                                "type": "any"
                            },
                            {
                                "name": "IsBeforeJuly",
                                "label": "IsBeforeJuly",
                                "type": "any"
                            },
                            {
                                "name": "DiscountRate",
                                "label": "DiscountRate",
                                "type": "any"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

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

Edit: I did still have to use a Parse date function to get this to work. I’m assuming it is because it was treating it as text and not as an actual date even though it works in other places. I’ve updated the code. I had to Parse all of dates (DateSubmission, Discount01End, and Discount02End). The discount dates I parsed in the set variable before this module.

Updated Code:

{{if(parseDate(8.DateSubmission; "YYYY-MM-DDTHH:mm:ss.SSSZ") < 36.Discount01End; 50; if(parseDate(8.DateSubmission; "YYYY-MM-DDTHH:mm:ss.SSSZ") < 36.Discount02End; 25; 0))}}

Original Message

@samliew Thank you for your help! I ended up simplifying it further. The whole goal with the scenario has been to use variables so I can quickly reuse this next year with that in mind and what you said about the dates already being in an acceptable format. I replaced the Parse and Format date with a variable from a set of Variables earlier that sets the two due dates.

I’ve included the code I ended up using for anyone’s reference later on.

{{if(8.DateSubmission < 36.Discount01End; 50; if(8.DateSubmission < 36.Discount02End; 25; 0))}}
2 Likes