GAS AI BuilderApps Script Assistant Sign in

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

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

More in Dates, text and numbers

Dates in Indonesian"Selasa, 3 November 2026" and "03/11/2026 14:05" in the script's time zone.Running numbers like INV-2026-0001A counter in Script Properties, raised under a lock so two people never get the same number; starts again each year.