Save non-ISO date in DB

Wappler: 5.1.0
Server: NodeJS
DB: PostgreSQL

Hello Wapplers,

From web-scrapping I’m receiving date in non-ISO format: ddd = 13.09.2022
Date in this format cannot be save in DB because it’s not in ISO format.
So I decided to modify value upon inserting: ddd.split('.')[2]+'.'+ddd.split('.')[1]+'.'+ddd.split('.')[0]

While searching I see many mentioning .toDate() transform but I receive an error "message": "Parser Error: Formatter \"toDate\" does not exist, expression {{ddd.toDate()}}",

And my question: is there more “Wappler way” to convert non-ISO date to ISO-date?

1 Like

Use a Set Value step called ddd_db
give it a value: (ddd.split('.')[2]+'-'+ddd.split('.')[1]+'-'+ddd.split('.')[0]).toDate()

Then use ddd_db in your queries/steps

I have changed the date part separator to - as I think that is what ISO should be

Appologies - I forgot to mentioned that "inserting: ddd.split('.')[2]+'.'+ddd.split('.')[1]+'.'+ddd.split('.')[0]" - did the trick and I was able to insert it.

My question was more about transforming non-ISO date to ISO date in “more Wappler way”.
But I guess if it’s working - it’s Wappler’s way! :slight_smile:

For non-iso formats, as far as I know, you have to do something like this. It is a ‘Wappler’ way as you can do it using built-in formatters. If it is something you need regularly and know the date format you are going to receive, it may be worth your time creating a custom formatter.

Thank you @bpj
Your answer added me some confident in my solution. :slight_smile:

1 Like