Moment Problems in App & Web

I'm using moment to format dates. In the IDE this displays perfectly, but in the Retool App, or web preview equivalent, it says Invalid Date.

I've tested with just inputting text rather than a query value, and it has the same error.


Is my syntax wrong or is this possibly a bug?


Adding screenshots


Retool App



I don't think this is working properly in the IDE as well.

When parsing a string to date, the date string should either be a ISO8601 or RFC2822 date time format or you should define the pattern of the date string as well.

ISO8601 moment("2023-08-10").format("DD.MM.yyyy")
RFC2822 moment("20230810").format("DD.MM.yyyy")

In your case it would be this to get a valid date:

1 Like

Many thanks Marc (@mbruijnpff),

That makes a lot of sense. I've been caught out with date formats in other software, but hadn't had any issues in any Retool web apps using this format.

Explicitly defining the input format and required format makes good sense - I will do that.

I'm wondering what Retool's advice is for formatting dates with moment (I haven't found anything in the docs (yet)), and whether I should revisit all the dates where I used that simpler method.

@jonj does this work right?

I debug you syntax in chrome with following warning

1 Like

Hi @AnsonHwang ,

Yes, Marc's suggestion works perfectly. The challenge is that the data (dates) are coming from sources, e.g. via API, and they aren't in either format, so I need to make sure they are interpreted correctly. Adding that input mask is the key from me.

Thanks for the tip with the Chrome console. I couldn't get it working as moment wasn't defined on a blank tab. That tip works on the Retool site or on though.