Help with Date Calculations please plus bespoke text

PLease can somebody help me with threse date calculation
Hi Guys

Please can you check with your planning dept on when you plan to deliver the following order {clipboard}.
This is a Acme Order and was purchased on {formdate: DD/MM/YYYY} with a {formmenu: 3 Day; default=5 Day; 6 Day; 7 Day; 8 Days; 10 Day; 14 Day; 21 Day} delivery lead time giving it a delivery date .
You sent out a eMail & SMS to the customer on the following date {formdate: DD/MM/YYYY} which is (count order date plus number of days befor message went out if same day as order put "Same Day") after the order.

The delivery date was due on (Purchae date + dropdown list selction in workdays only) as you can see it iit should have been deliverd (count how many days after due delivery date if delivery is same day put Today or number of days late.)

Examples 1

Hi Guys

Please can you check with your planning dept on when you plan to deliver the following order 12345.
This is a Acme Order and was purchased on 03 Jan 2023 with a 5 Day delivery lead time giving it a delivery date of 10 Jan 2023.
You sent out a eMail & SMS to the customer on the following date 04 Jan which is 1 day after the order.

The delivery date was due on 10 Jan as you can see it is 4 business days late.

Examples 2

Hi Guys

Please can you check with your planning dept on when you plan to deliver the following order 12345.
This is a Acme Order and was purchased on 03 Jan 2023 with a 8 Day delivery lead time giving it a delivery date of 13 Jan 2023.
You sent out a eMail & SMS to the customer on the following date 03 Jan which is same day of order.

The delivery date was due Today 13 Jan as you can see it is 0 business days late.

Is this something you are looking for?

Please can you check with your planning dept on when you plan to deliver the following order {clipboard}.
This is a Acme Order and was purchased on {formdate: DD MMM YYYY; name=purchasedOn} with a {formmenu: 3; default=5; 6; 7; 8; 10; 14; 21; name=deliverydays} Day delivery lead time giving it a delivery date of {time: DD MMM YYYY; at={=purchasedon}; shift=+{=deliverydays}D(skip=SAT, SUN); pattern=DD MMM YYYY}.
You sent out a eMail & SMS to the customer on the following date {note: preview=yes; insert=no}{formdate: DD/MM/YYYY; name=sentday}{endnote}{note: preview=no; insert=yes}{time: DD MMM; at={=sentday}}{endnote} which is {if: diffdays <=1}Same Day{else}{=diffdays}days{endif}(count order date plus number of days befor message went out if same day as order put "Same Day") after the order.
The delivery date was due on (Purchae date + dropdown list selction in workdays only) as you can see it iit should have been deliverd (count how many days after due delivery date if delivery is same day put Today or number of days late.){note}{diffdays=datetimediff(datetimeparse(purchasedon, "DD MMM YYYY"), datetimeparse(sentday,
"DD/MM/YYYY"), "D")}{endnote}

I changed dropdown from 3 Days to 3 to avoid striping of Days from the value.
A date field should have year, so I used two {note}s, one with preview=yes and insert=no. Which would show for you during selecting a value, but does not insert into the actual text.
Then another note, with preview=no, and insert=yes. Then formatted the string without year.

I used two date functions datetimediff and datetimeparse to calculate the days and show them. For more functions check here .

I assume you need the date calculating only week days. So I used this method.

Hi the text in brakets is only for here to help people solving it like yourself not need in live enviroment

How about this:

Please can you check with your planning dept on when you plan to deliver the following order {clipboard}.
This is a Acme Order and was purchased on {formdate: DD MMM YYYY; name=purchasedOn} with a {formmenu: 3; default=5; 6; 7; 8; 10; 14; 21; name=deliverydays} day delivery lead time giving it a delivery date of {=`expected delivery`}.
You sent out an Email & SMS to the customer on the following date {note: preview=yes; insert=no}{formdate: DD/MM/YYYY; name=sentday}{endnote}{note: preview=no; insert=yes}{time: DD MMM; at={=sentday}}{endnote} which is {if: `message to order diff days` <=0}the same day{else}{=`message to order diff days`} days after the order.{endif}
The delivery date was due on {=`delivery due date`}. As you can see it should have been delivered {if: `days past delivery due` == 0} today {else} {=`days past delivery due`} days ago{endif} {note}{`message to order diff days`=datetimediff(datetimeparse(purchasedon, "DD MMM YYYY"), datetimeparse(sentday,
"DD/MM/YYYY"), "D")}{`expected delivery`={time: DD MMM YYYY; at={=purchasedon}; shift=+{=deliverydays}D(skip=SAT, SUN); pattern=DD MMM YYYY}} {`delivery due date`={time: DD MMM YYYY; at={=purchasedon}; shift=+{=deliverydays}D(skip=SAT, SUN); pattern=DD MMM YYYY}} {`days past delivery due`=datetimediff(datetimeparse(`expected delivery`, "DD MMM YYYY"), {time: YYYY-MM-DD}, "D")}{endnote}

1 Like

HI it is 99.9% there but i see a code bug in TB if you select You sent out an Email & SMS to the customer on the following date and pick 14 Jan it should say 1 day but it remains same day but if you pick 15 Jan it shows 2 days ????

Fixed.
Do we mind is we post a simplified version of this snippet in our gallery?

No go for it it should be helpful