I currently get a date from calendar control and using luxon I add days, minutes to it and change it to LongHours format like below: newValue : is value i get from frontend(calendar control)
let formattedDate: any;
FormattedDate = DateTime.fromJSDate(new Date(newValue)).plus({ days: 1, hours: 3, minutes: 13, seconds: 10 }).toLocaleString(DateTime.DATETIME_HUGE_WITH_SECONDS)
console.log(formattedDate);
const formattedDateParsed = DateTime.fromJSDate(new Date(formattedDate));
const newValueParsed = DateTime.fromJSDate(new Date(newValue));
var diffInMonths = formattedDateParsed.diff(newValueParsed, ['months', 'days', 'hours', 'minutes', 'seconds']);
diffInMonths.toObject(); //=> { months: 1 }
console.log(diffInMonths.toObject());
Currently the formattedDateParsed is coming as 'Null'
Can I get some help as how to parse the date so that diff can be calculated
newValue
? – Stinkynew Date
, while if it is a string I fear new Date cannot parse it correctly, you can probably usefromFormat
– Stinky