Hi, I am trying to get the past 7 days from the collected items based on the Creation Date from the current date…see the code below
const createdDate = new Date(collected_solution_field_created_on_formatted);
const days = date_fns.differenceInCalendarDays(current_date_formatted, createdDate);
if (days <= 7) {
// within last 7 days
if (collected_team_member_field_prospect_accounts_decimal_value > 0) {
var_nc_count =var_nc_count + 1;
}
}
return var_nc_count;
so when I use the NC_Count to update the field, it gets updated as NaN…Not getting what I’m doing wrong here… @Jason if you could help? TIA
You need to parse the second date(current_date_formatted ):
const createdDate = date_fns.parseISO(collected_nexus_journal_created_at_formatted); //parse the date
const days = date_fns.differenceInCalendarDays(date_fns.parseISO(current_date_formatted), createdDate); //parse the secnond date
if (days <= 7) {
// within last 7 days
if (collected_nexus_journal_app_record_id > 0) {
var_count = var_count + 1;
}
}
console.info(var_count);
However I am not sure I would have expected a NaN if you had the variable initialised outside of your loop i would have expected 0 or whatever number you were starting at.
Thanks for the quick reply, will try this but to make sure the collected date is the created on field which contains the time as well like 2025-11-15 05:41:47