Can someone please help me with my code
# 🤝help
w
I am trying to write a validation for date in my bot.The days should be within 100 days after todays date Below is my code const { year, month, day } = input; // Check if the provided date is a valid Date object const isValidDate = !isNaN(Date.parse(
${year}-${month}-${day}
)); if (!isValidDate) { // The provided date is not valid return false; } // Get the current date and time (with time set to midnight) const today = new Date(); today.setHours(0, 0, 0, 0); // Calculate the time difference between today and the input date in milliseconds const timeDifference = Date.parse(
${year}-${month}-${day}
) - today.getTime(); // Convert the time difference to days const daysDifference = timeDifference / (1000 * 60 * 60 * 24); // Check if the days difference is less than or equal to 100 return daysDifference >= 0 && daysDifference <= 100; But it is not working since if I keep 2023-08-03.It doesnt return true.Why is that?
a
hey @worried-musician-44929 are you running this in your capture card's validation or in a separate execute code card?
w
I am running it there

https://cdn.discordapp.com/attachments/1136236910252150824/1136602035538628628/Screenshot_95.png

a
there's a bug right now with custom validation functions. As a workaround, you can try putting it in an execute code card after the capture card.
w
function checkDateWithin100DaysAfterToday(_inputDateISO: any){ const today = luxon.DateTime.now().startOf('day') const inputDate = luxon.DateTime.fromISO(workflow.Date).startOf('day') const maxDate = today.plus({ days: 100 }) if (inputDate > maxDate) { return('The input date is more than 100 days after today') } else { return('The input date is within 100 days after today') } } i have used the expression card but still not working
a
you would need to call the function using the saved variable from the capture card as input
18 Views