Check if value is date

Hi!

I have a module in OpenAI that reads values from an image. I need to get some date values and format them, getting the full date, only month or years.
There are two dates: Start Date and End Date. End Date is not always present, so I prompted OpenAI to set it as null, or nothing. The problem is that sometimes, the value returns as “Not applicable”, “Nothing”, or any other text.

So, when I save the value on a Google Sheet using the formatDate formula, it fails.

The question is: ¿How to check if a value is in Date format, before executing a date formula?

EDIT: I want to make it clearer: If the image has no End Date, OpenAI is prompted to return a null value, or nothing. Sometimes it passes a text stating nothing.
In the Google Sheets / Add a Row , on the End Date field, I want to have this formula: {{formatDate(38.EndDate; " DD-MM-YYYY")}}

That formula is set on the StartDate, because there’s always a value

But if the value is a text string different from a date, it fails. Right now, I stopped formatting it.

Welcome to the Make community!

You can use the built-in functions if length replace with a regular expression to check the format.

e.g.:

{{if(length(replace(1.string; "/^\d{2}-\d{2}-\d{4}$/"; emptystring)) = 0; true; false)}}

Output:

For more information, see the function documentation in the Help Center and do the tutorials in the Make Academy.

Hope this helps! Let me know if there are any further questions or issues.

@samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

Module Export - quick import into your scenario

You can copy and paste this module export into your scenario. This will import the modules (with fields/settings/filters) shown in my screenshots above.

  1. Move your mouse over the line of code below. Copy the JSON by clicking the copy button on the right of the code, which looks like this:

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

  3. Click on each imported module and re-save it for validation. There may be some errors prompting you to remap some variables and connections.

JSON module export — paste this directly in your scenario

{"subflows":[{"flow":[{"id":269,"module":"util:SetVariables","version":1,"parameters":{},"mapper":{"variables":[{"name":"date1","value":"abcdef"},{"name":"date2","value":"31-01-2025"}],"scope":"roundtrip"},"metadata":{"designer":{"x":356,"y":-1441}}},{"id":268,"module":"util:SetVariables","version":1,"parameters":{},"mapper":{"variables":[{"name":"date1","value":"{{269.date1}}"},{"name":"isValidFormat","value":"{{if(length(replace(269.date1; \"/^\\d{2}-\\d{2}-\\d{4}$/\"; emptystring)) = 0; true; false)}}"},{"name":"date2","value":"{{269.date2}}"},{"name":"isValidFormat2","value":"{{if(length(replace(269.date2; \"/^\\d{2}-\\d{2}-\\d{4}$/\"; emptystring)) = 0; true; false)}}"}],"scope":"roundtrip"},"metadata":{"designer":{"x":602,"y":-1441}}}]}],"metadata":{"version":1}}

Note: Did you know you can reduce the size of blueprints and module export code like the above, using the Make Blueprint Scrubber?

Thank you very much! I’ll try this ASAP