Timestamp in function problems

Hi Orio,

I didnt study your javascript in depth but if it was me i would go to the original idea of using the Moment js library that makes datetime calculations easier with its extended library.

In order for the module library to be accesible is your function nodes you edit the functionGlobalContext section of the Node-red settings.js file :

 functionGlobalContext: {
           moment:require('moment')
        // os:require('os'),
        // jfive:require("johnny-five"),
        // j5board:require("johnny-five").Board({repl:false})
    },

and in the Function node :

let moment = global.get('moment')

let currentTime = moment();
let sqlTime = moment('20201021075538','YYYYMMDDHHmmss'); // convert to moment
let duration = sqlTime.from(currentTime)

node.warn(currentTime)
node.warn(sqlTime)
node.warn(`Duration : ${duration}`)

//node.send({'payload': `This is the year: ${moment().format('YYYY')} as a string`})

Example flow :

[{"id":"bb4051ca.65a4e8","type":"inject","z":"54aa25ce.417e1c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":300,"y":380,"wires":[["345d113b.aaa426"]]},{"id":"345d113b.aaa426","type":"function","z":"54aa25ce.417e1c","name":"","func":"let moment = global.get('moment')\n\nlet currentTime = moment();\nlet sqlTime = moment('20101021075538','YYYYMMDDHHmmss');\nlet duration = sqlTime.from(currentTime)\n\nnode.warn(currentTime)\nnode.warn(sqlTime)\nnode.warn(`Duration : ${duration}`)\n\n//node.send({'payload': `This is the year: ${moment().format('YYYY')} as a string`})","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":380,"wires":[["9cba50f8.4d01d8"]]},{"id":"9cba50f8.4d01d8","type":"debug","z":"54aa25ce.417e1c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":380,"wires":[]}]

image