I’m experiencing issues with date filtering in Airtable. I want to retrieve a specific record where the Date field matches 8/01/2022. I’ve set up a Date field in the table for storing dates. However, my filter seems to be malfunctioning as it always returns the first entry instead of the date I’m targeting.
Here’s the code I’m currently using:
let specifiedDate = new Date("08/01/2022").toISOString().slice(0, 10);
const airtableInstance = new Airtable({ apiKey: apiKeyValue }).base(baseIdValue);
airtableInstance("tableRecords")
.select({
filterByFormula: `"DATESTR({Date})='${specifiedDate}'"`,
view: "Main view",
})
.eachPage(
function processPage(recordsList, getNextPage) {
recordsList.forEach(function (recordItem) {
let resultItem = {
dateField: recordItem.get("Date"),
activityField: recordItem.get("activities"),
};
updateResults(resultItem);
});
try {
getNextPage();
} catch {
return;
}
},
function done(error) {
if (error) {
console.error(error);
return;
}
}
);
The date 2022-07-29 corresponds to the first entry in my table. Every time I check the ISO string, it confirms the correct date of 8/01/2022. I’m unsure what I’m doing wrong with the date filtering.
Ah, I see what’s wrong - you’ve got nested quotes causing problems. Use DATETIME_PARSE('2022-08-01') instead of datestr. It’s cleaner and handles format conversion automatically. Also check your timezone settings in the Airtable base - I’ve seen filters break when the timezone doesn’t match your local date parsing.
Hit this same issue 6 months ago on a project tracker. Wasted hours debugging before I caught those sneaky quotes.
Your date format looks good, but if you’re still stuck, try the raw string ‘2022-08-01’ instead of converting with JavaScript. Sometimes simple beats clever - especially with timezone weirdness.
Pro tip: console.log your formula string before sending it to Airtable. You’ll spot syntax problems instantly.
Your filterByFormula has extra quotes around it. You’re using DATESTR({Date})='${specifiedDate}' which treats the whole thing as a literal string instead of a formula. Drop the outer quotes: DATESTR({Date})='${specifiedDate}'. Also check your date format matches what Airtable wants - YYYY-MM-DD works best in my experience. Try logging the formula string before you use it too. I had the same issue last month and that’s how I caught these syntax errors.
Your date conversion logic is the problem. Don’t use toISOString().slice(0, 10) - format it as YYYY-MM-DD directly or stick with Airtable’s built-in date functions. I’ve hit this same issue with international date formats. Try IS_SAME({Date}, '2022-08-01', 'day') instead of DATESTR. It’s way more reliable for exact matches and handles timezone problems much better. IS_SAME ignores time components and formatting quirks that mess up your filters.