CRM邮件模板日期变量开发请求:动态生成连续工作日文本
Hey there, let's get that static "Wednesday or Thursday" text replaced with dynamic, date-aware weekdays so your emails feel more timely and personalized. Here are a couple of practical solutions depending on what scripting/templating your CRM supports:
Option 1: JavaScript (for web-based CRMs that allow embedded scripts)
First, add this reusable function to your template (usually in a hidden script block at the top of the email):
function getNextTwoWorkdays() { const dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; const today = new Date(); const upcomingWorkdays = []; let nextDay = new Date(today); // Keep looping until we collect two valid workdays while (upcomingWorkdays.length < 2) { nextDay.setDate(nextDay.getDate() + 1); const dayIndex = nextDay.getDay(); // Skip weekends (Sunday = 0, Saturday = 6) if (dayIndex !== 0 && dayIndex !== 6) { upcomingWorkdays.push(dayNames[dayIndex]); } } return `${upcomingWorkdays[0]} or ${upcomingWorkdays[1]}`; }
Then, in the body of your email where the fixed text was, replace it with a call to this function:
<p>Dear Mr X.</p> <p>Is there a time <script>document.write(getNextTwoWorkdays());</script> that we can connect to go over next steps?...</p>
Option 2: Liquid Templating (for CRMs like HubSpot, Shopify)
If your CRM uses Liquid (no external scripts needed), use this snippet instead:
{% assign today = 'now' | date: '%w' %} {% assign nextWorkdays = '' %} {% assign daysCollected = 0 %} {% assign currentDay = today | plus: 1 %} {% while daysCollected < 2 %} <!-- Wrap around to start of the week if we pass Saturday --> {% if currentDay > 6 %} {% assign currentDay = currentDay | minus: 7 %} {% endif %} <!-- Skip Sunday (0) and Saturday (6) --> {% if currentDay != 0 and currentDay != 6 %} {% assign dayName = currentDay | date: '%A' %} {% if daysCollected == 0 %} {% assign nextWorkdays = dayName %} {% else %} {% assign nextWorkdays = nextWorkdays | append: ' or ' | append: dayName %} {% endif %} {% assign daysCollected = daysCollected | plus: 1 %} {% endif %} {% assign currentDay = currentDay | plus: 1 %} {% endwhile %} <p>Dear Mr X.</p> <p>Is there a time {{ nextWorkdays }} that we can connect to go over next steps?...</p>
Quick Test Cases to Verify:
- If today is Monday → returns "Tuesday or Wednesday"
- If today is Thursday → returns "Friday or Monday"
- If today is Friday → returns "Monday or Tuesday"
- If today is Sunday → returns "Monday or Tuesday"
Just adapt the syntax if your CRM uses a different language (like PHP or Python)—the core logic stays the same: skip weekends and grab the next two valid workdays.
内容的提问来源于stack exchange,提问作者jon Myers

