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
x
3
1
reminder_date: '2021-02-15T08:00:00.000Z',
2
reminder_time: '2021-02-09T17:00:00.000Z'
3
But i want to store it in my db as one single value like
JavaScript
1
2
1
'2021-02-15T17:00:00.000Z'
2
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
1
4
1
let reminder_date = '2021-02-15T08:00:00.000Z';
2
let reminder_time = '2021-02-09T17:00:00.000Z';
3
let reminder_date_time = reminder_date.substr(0, 11) + reminder_time.substr(11);
4
console.log(reminder_date_time);