Skip to content
Advertisement

How to combine Date and Time from 2 different var’s in NodeJS

I have a User Input which consists of a Date and a Time Input. Both of those values are send as a full date like

JavaScript

But i want to store it in my db as one single value like

JavaScript

what is the best approach to achieve that ? split the strings on T and then combine or is there a simple way i can take the date part and the time part and create a new dateTime to save

Advertisement

Answer

If the two items are strings, you could simply use the JavaScript substr function to get the first 11 characters from reminder_date and the second part of reminder_time (starting from 11), then concatenate them, e.g.

JavaScript
Advertisement