Transform the provided timestamp into a format compatible with InfluxDB timestamp requirements

My Incoming Date is in the following format : 15.08.2017 23:03:23.120000

Currently, I am utilizing the Node-Red Platform to convert msg.payload.time into an Influx timestamp. However, I am encountering the following error:

"Error: Expected a numeric value for the timestamp, but received '15.08.2017 23:03:23.120000'!".

If anyone could assist me with the script required to convert this timestamp to an Influxdb timestamp, it would be greatly appreciated.

Answer №1

InfluxDB requires unix timestamps and msg.payload.time could be in string format, leading to the error you encountered.

To convert a date into a timeStamp, you can utilize JavaScript's Date functionality as follows:

new Date('<your-date-string>').valueOf()

The date-string should follow the 'YYYY-MM-DD hh:mm:ssZ' format.

In this scenario, where the msg.payload.time is in dd.mm.yy hh:mm:ssZ format, additional steps are necessary.

You can adjust your code like so:

const incomingDate = msg.payload.time;

// extract the date dd.mm.yyyy from the incoming Date String
const splittedDate = incomingDate.split(' ');

// Convert the date from dd.mm.yyyy to yyyy-mm-dd format
let date = splittedDate[0].split('.').reverse().join('-');

// Store time value separately for later use.
const time = splittedDate[1];

// merge date and time to form yyyy-mm-dd hh:mm:ssZ format
const datetime = `${date} ${time}`

// assign the timestamp value to fields.time
fields.time =  new Date(datetime).valueOf();

Below is a functional demonstration:

const incomingDate = '15.08.2017 23:03:23.120000';
const splittedDate = incomingDate.split(' ');
let date = splittedDate[0].split('.').reverse().join('-');
const time = splittedDate[1];
const datetime = `${date} ${time}`
console.log(datetime);
console.log(new Date(datetime).valueOf())

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Anticipated a task or method invocation but encountered an expression instead no-unused-expressions (line 14/15)

I can't seem to figure out the issue with my code. Despite trying to fix it multiple times by adjusting lines 14/15, I keep encountering the same error. If anyone has any insights or suggestions on what might be causing this problem, I would greatly a ...

Searching recursively through a PHP array with path information

Here is the haystack array that I am dealing with: $array = [ [ "name" => "Intro", "id" => "123", "children" => [ "name" => "foo", "id" => "234", "children" => [ "name" => "m ...

Converting a variable with a cloned object from jQuery to vanilla JavaScript

const clonedBoardCode = $('#board_code').contents().clone(false); alert( clonedBoardCode.filter('div').eq(x).children().eq(y).text() );//need to fix this I am looking for a code similar to this $('#board_code_dup > div') ...

trouble encountered while parsing JSON information using JavaScript

[ [ { "Id": 1234, "PersonId": 1, "Message": "hiii", "Image": "5_201309091104109.jpg", "Likes": 7, "Status": 1, "OtherId": 3, "Friends": 0 } ], [ { "Id": 201309091100159, "PersonI ...

The issue of character encoding complications in JSON data formats

Whenever I convert an array to JSON, it displays "u00e1" instead of the proper character á. Is there a way to fix this issue with character encoding? Thank you ...

Automatically generated webpage smoothly scrolling downward

Within my application, I have been developing dynamic pages with a CSS property of overflow-y:auto applied to the page container. Everything seems to be working fine, The issue arises when the page loads and the height exceeds that of the container. While ...

Angular test failure: Receiving $injector:unpr Unknown Provider error despite having no dependencies

Encountering this specific error, where my injector seems to have trouble resolving a necessary dependency. Even with my limited understanding of Angular, it doesn't seem like this code should rely on any external modules. The code functions properly ...

Steps to correcting the return data type of the final promise in a chain?

Seeking a solution to return the last promise in a chain as the outcome of a function. Currently utilizing TypeScript 1.7 and native, ES6 promises. Despite attempting different approaches, I've found that TypeScript interprets the first promise (Uint ...

Guide on how to have two controllers execute identical tasks in Angular while modifying the appearance of the website

Trying to recreate Google's homepage functionality using Angular has been challenging for me. Despite watching Egghead videos and studying the API extensively, I couldn't find a specific example for this behavior. Here's what I aim to achiev ...

What is the proper way to arrange this particular array?

I'm having trouble with sorting this array. The array contains objects with SortTime and Operation values like this: array = [ {SortTime : 123456, Operation : Assigning}, {SortTime : 4567 , Operation: Assigning}, {SortTime : 123456 , Operation: Assi ...

Using Ajax to invoke a C# webmethod

I'm trying to call a webmethod defined in this specific class <%@ WebService Language="C#" Class="emt7anReyady.myService" %> using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Linq; usi ...

Initializing a table with data will only function properly when a breakpoint is set

Using the bootstrap-table library, I initialize a table with data fetched via ajax request. var arr = []; var getRows = function () { $.ajax({ type: "GET", url: hostUrl, contentType: "app ...

Creating an intricate table layout using AngularJS and the ngRepeat directive

I'm attempting to create a table similar to the one shown in the image below using HTML5. https://i.sstatic.net/DiPaa.png In this table, there is a multi-dimensional matrix with Class A and Class B highlighted in yellow. Each class has three modes ( ...

Utilize the function of express

The following code is not behaving as expected: var express = require('express'); var app = express(); app.use(function(req, res, next) { console.log('first statement'); next(); }, function (req, res, next) { console.log('se ...

Error in TypeScript when utilizing generic callbacks for varying event types

I'm currently working on developing a generic event handler that allows me to specify the event key, such as "pointermove", and have typescript automatically infer the event type, in this case PointerEvent. However, I am encountering an error when try ...

Preserve the indexes of the array

In my application, I have a tree feature where users can drag and drop elements to change their positions. After each change, I need to send the serialized array to be saved. Here is an example of the tree: Economics Blogging General Dev Japan Productiv ...

AngularJS: Setting the hash prefix for $locationProvider to "!"

Is there a way to show the URL as "www.test.com/!#" instead of "www.test.com/#!" when using $locationProvider.hashPrefix("!")? I want the exclamation mark before the hash, not after it. Thanks var app = angular.module('app', []); app.config(fu ...

Phantom writing reminiscent of the ghostly prose found on a Tumblr registration

Is there a way to create a URL field similar to the one on ? It's the field where the text is faded and when you click on it to type, it automatically appends ".tumblr.com" that cannot be erased or highlighted. The JavaScript used for this feature is ...

Encountering a SyntaxError - the missing '}' after the property list, check out the URL for more details: http://localhost/mcportal/public/post/comment/196

Can anyone help with debugging this issue? I have an Ajax request in a PHP view file and encountering errors. Here is the code snippet: $( "body" ).on ("keypress", "#comment", function( event ) { if(event.which == 13) $.ajax({ ...

Steps for assigning an id to an element using Selenium

When using Selenium, you have the ability to access the underlying DOM of the browser being manipulated through IWebElement instances. For example: IWebElement domWrapper = driver.FindElement(By.Name("q")); But what if you have the "domWrapper" instance ...