How can I convert the value I get with date range picker to two seperate date and time?

Issue

I need to get the start date, start time, end date and end time values ​​separately that I got with the daterangepicker.

startinnerDate = document.getElementById('reservationtime').value;

Incoming value: "07/14/2021 12:00 AM – 08/10/2021 11:00 PM"

how can i separate it?

Solution

Not the optimal one and not flexible, but very clear for understanding

const startinnerDate = "07/14/2021 12:00 AM - 08/10/2021 11:00 PM"
const [start, end]  = startinnerDate.split(' - ');
const [startDate, startTime, startTimePeriod] = start.split(' ');
const [endDate, endTime, endTimePeriod] = end.split(' ');
console.log('date >>> ', startDate, '| time >>> ', startTime + ' ' + startTimePeriod);
console.log('date >>> ', endDate, '| time >>> ', endTime + ' ' + endTimePeriod);

Answered By – Alex

Answer Checked By – Marie Seifert (AngularFixing Admin)

Leave a Reply

Your email address will not be published.