I’m attempting to display a calculation between a recorded date and now. Here is the format I am using, which is a timestamp format using “F jS, Y g:i A”
The JS is as follows which I was able to add a line (after getting a NaN) to check for date format error. And for some reason, it’s claiming the format is the issue.
Does it expect a specific format?
// Access the application_date from the global variable
const applicationDate = collections['834er0nwe0nw0bwgw']?.['data']?.['application']?.['application_date'];
// Parse the application_date to a JavaScript Date object
const parsedApplicationDate = new Date(applicationDate);
// Check if parsedApplicationDate is a valid date
if (isNaN(parsedApplicationDate.getTime())) {
return "Invalid date"; // Or handle the error appropriately
}
// Get the current date and time
const now = new Date();
// Calculate the difference in milliseconds
const diffInMilliseconds = now.getTime() - parsedApplicationDate.getTime();
// Convert the difference from milliseconds to days
const diffInDays = diffInMilliseconds / (1000 * 60 * 60 * 24);
// Round the number of days to the nearest whole number
const roundedDiffInDays = Math.round(diffInDays);
// Return the number of days
return roundedDiffInDays;