Date / Format in a script

Hi,
After an HTTP Request I get an array. In this array I've got an object (date) formated like this : 2022-12-09 and I would like to convert it like this 09/12/2022. If I use the Moment Node I know how to do that for one element of the array but I don't know how to use this node in a script to convert the whole array. Is it possible or do I need to write a script without the Moment Node and how ?
Thx.

Could you run the message through a Split node, Moment and then Join it back together?

Unfortunaletly not :frowning:

Can you copy and paste here an example of your data?

{"data_id":"9701816","iso":"180","event_id_cnty":"DRC27730","event_id_no_cnty":"27730","event_date":"2022-12-09","year":"2022","time_precision":"1","event_type":"Battles","sub_event_type":"Armed clash","actor1":"ADF: Allied Democratic Forces","assoc_actor_1":"","inter1":"2","actor2":"Military Forces of the Democratic Republic of Congo (2019-)","assoc_actor_2":"Military Forces of Uganda (1986-)","inter2":"1","interaction":"12","region":"Middle Africa","country":"Democratic Republic of Congo","admin1":"Nord-Kivu","admin2":"Beni","admin3":"Ruwenzori","location":"Bulongo","latitude":"0.3260","longitude":"29.6928","geo_precision":"1","source":"Radio Okapi","source_scale":"National","notes":"On 9 December 2022, ADF clashed with joint FARDC - UPDF forces in Bulongo (Ruwenzori, Beni, Nord-Kivu) whilst the group was attempting to assault the city center. Early warning of locals enabled fast reaction of military forces who pushed away the assailants. Casualties unknown.","fatalities":"0","timestamp":"1670859656","iso3":"COD"}

That's not an array but an object.
Is it just one element of an array of similar events?

You can use moment in a Change node, though I'm not familiar with the syntax. There is an example here

So a split, a change node applying your reformat change to msg.payload.event_date and a join should work.

Yes, I've got at least 500 objects per array.

I'm going to try that. Thx.

You can also use the JavaScript INTL library in node.js - so you can either reference the library in your settings.js globals section (and get a reference to it in your function) or, if you allow function nodes to use local libraries (see settings.js), you could add it direct to the function node and use it directly.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.