Turn text from the page into a date
Apps Script recipes › Dates, text and numbers
An <input type="date"> sends "2026-11-03"; new Date() on it gives midnight UTC, a day early or late in some zones. This reads it in the script's time zone.
File Code.gs
/** "2026-11-03" or "2026-11-03T14:05" → Date in the script's time zone. */
function parseDate_(text) {
const s = String(text || '').trim();
if (!s) return null;
const withTime = /T\d\d:\d\d/.test(s);
return Utilities.parseDate(s.slice(0, withTime ? 16 : 10), Session.getScriptTimeZone(), withTime ? "yyyy-MM-dd'T'HH:mm" : 'yyyy-MM-dd');
}
/** Days from today to a date (negative = in the past). */
function daysUntil_(date) {
const day = 24 * 60 * 60 * 1000;
const start = new Date(); start.setHours(0, 0, 0, 0);
const end = new Date(date); end.setHours(0, 0, 0, 0);
return Math.round((end - start) / day);
}
Good to know
- Utilities.parseDate uses the time zone you give it, so the date stays the same day.
Let the AI put it in your appGAS AI Builder knows every recipe here. Describe your app and it uses this code where it fits, in a Google Apps Script project in your own Drive.
Use it in a project