Add 90 days to a date that I enter (not current date)

I often need to print a date and calculate 90 days from that date.

For example:

”Your expiration date is December 15, 2025. Be sure to rejoin before March 15, 2026.”

I want to be prompted to enter the 12/15/25 date and have the snippet add 90 days to it. I am only finding example that show adding 90 days to the CURRENT date, not a date that the user enters.

If on a Mac, you could do this quite easily with Shortcuts. Run the shortcut, get prompted for date, enter, and then it will build your text string as per your example and pop it onto your clipboard for pasting.

Having thought about this a bit longer, with the new date picker fill-in, you can do this in Textexpander when combining the fill-in with JavaScript.

In the screen grab, you’ll see I’ve a JavaScript Content Type snippet with a date picker fill-in at the top, named start_date. When setting this up, you’ll need to ensure you are using YYYY-MM-DD format. Then, you just paste in the script after it, as per the below…

// Read the Date Picker fill-in value by its field name (“start_date")

var s = (TextExpander.filledValues && TextExpander.filledValues.start_date || "").trim();

// Expect YYYY-MM-DD (Important ! set this in the Date Picker settings)

var m = s.match(/^(\d{4})-(\d{2})-(\d{2})$/);

if (!m) {

'Couldn’t parse the date. Date Picker returned: "' + s + '"';

}

var startDate = new Date(parseInt(m[1],10), parseInt(m[2],10)-1, parseInt(m[3],10));

var endDate = new Date(startDate);

endDate.setDate(startDate.getDate() + 90);

function fmtUS(d) {

return d.toLocaleDateString("en-US", { month: "long", day: "numeric", year: "numeric" });

}

"Your expiration date is " + fmtUS(startDate) +

". Be sure to rejoin before " + fmtUS(endDate) + "."; 

So when expanding the snippet, your start_date picker will appear. Select the date from the calendar, and then click on Expand. And that’s it. Your expiration sentence will expand with the appropriate dates.

1 Like

Thank you for that. I’ve set it up as noted, but am getting an error when I expand it.

Here’s what I have for the setup:

When I run it, a window comes up with a date picker at the top and all the code below it. When I select my date and click expand, I get “JavaScript Error: TypeError - null is not an object (evaluating ‘m[1]’)”

You’ve named the date picker variable StartDate and not start_date as per the instructions. That’s why it’s failing as your JS is not seeing the variable. Best just start over, following the instructions as outlined.