Need help with addDatePicker command

I need to prompt the user to select beginning and end dates for calendar entry. How do I do this using “addDatePicker” command. Any documentation on this ? I would appreciate a simple example script :

  • displaying date picker
  • and creating two variables containing “begin date” and an “end date” after selection has been made by user.

Thanks in advance.

The scripting documentation for the prompt contains an example for the date picker.

p.title = "Hello";
p.message = "World!";

p.addDatePicker("startDate", "Start date", new Date(), {
  "mode": "date"
p.addDatePicker("endDate", "End date", new Date(), {
  "mode": "date"

That’s a rough example which should get you started.

I have come across this script and as my js knowledge is next to nil, this is not of much help to me. Thanks anyway.

This expands on the information highlighted by @RosemaryOrchard.

var p = Prompt.create();

p.title = "Date Selection";

p.addDatePicker("dateBegin", "Begin date", new Date(), {
  "mode": "date"

p.addDatePicker("dateEnd", "End date", new Date(), {
  "mode": "date"


if (
	if (p.buttonPressed == "OK")
		alert("Begin date is " + p.fieldValues["dateBegin"] + "\nEnd Date     is " + p.fieldValues["dateEnd"]);

This link in theory should be able to direct install the example - please verify the content before running it. It is provided as is.

When run you may see that you are getting full time stamps and not a simple date back. As a result you may want to do some manipiulation of the dates as they stand to remove the time (and maybe(?) the time zone) … assuming you get the sort of result I get.

But that’s a slightly different question and the sort of thing you will probably need to work with in order to do whatever you want to do next with the dates captured.


Thank you ver much - exactly what I was looking for.

Yes you were right :smiley: I would be grateful if you could show me how to format the date output without time zone and 24 hr time format - hours and minutes only. Thanks v much.

See if this helps you get a step further.

alert(p.fieldValues["dateBegin"].toString("yyyy-MM-dd HH:mm"));

Add it after the last alert line and see what it outputs.

Thanks Stephen -

Formated present date as follows:
var presentDate = new Date().toString(“dddd, dd MMMM yyyy HH:mm”)

And it works !

and, FWIW, a minor variation, with a few alternative idioms:

(() => {
	'use strict';

		p = Object.assign(
				Prompt.create(), {
				title: 'Date selection'
		dte = new Date(),
		dctMode = {
			'mode': 'date'
		strFormat = 'dddd, dd MMMM yyyy HH:mm',
		strBegin = 'From: ',
		strEnd = 'To: ';

	return (
		p.addDatePicker('dateBegin', strBegin, dte, dctMode),
		p.addDatePicker('dateEnd', strEnd, dte, dctMode),
		p.addButton('OK'), ? (
			p.buttonPressed === 'OK' ? (
					strBegin + 
					p.fieldValues.dateBegin.toString(strFormat) + '\n' +
					strEnd + 
			) : false
		) : false

Thanks for your help.