The date question type (type: date
) defines a date control that is activated by clicking in a text field. Respondents can either type the date into the field, or use the automated date picker control that is displayed when the respondent clicks in the field. Specifying a data type can control the format of the date being entered. By default, dates selected via the picker are displayed in a mm/dd/yyyy format.
The example below shows the basic usage of the date question type. The calendar control will highlight the default date (typically the current date). Respondents can navigate to other dates, and as they hover over another date, it will be circled, while the initial date will then be shown in a filled-in, gray circle. The date that has been clicked on will be enclosed in a colored-in circle, and its full date will be displayed in the text field.
If the respondent instead enters a date in the text field, the calendar will navigate to the inputted date. The matching date will be enclosed in a colored-in circle.
Respondents can navigate to other months by clicking the left/back or right/forward arrows at the top of the calendar.
Syntax
Basic
X. This question would like you to enter or select a date. type: date
Tags
Below are some common tags associated with the date
question type. The following tags may be used in conjunction with one another to get the functionality and date display you're looking for:
Tag | Description |
---|---|
default date |
When the calendar control appears, indicates the date the calendar begins with. A properly formatted date or variable that contains a string of a date can be used as the tag's value. See below for date input formats. |
start date |
Indicates a start date for the date entry. Dates prior to the specified start date are disabled in the calendar control and cannot be selected. If the date is entered manually, the system will validate and display an error if the date entered is prior to the specified start date. A properly formatted date or variable that contains a string of a date can be used as the tag's value. See below for date input formats. |
end date |
Indicates an end date for the date entry. Dates after the specified end date are disabled in the calendar control and cannot be selected. If the date is entered manually, the system will validate and display an error if the date entered is after the specified end date. A properly formatted date or variable that contains a string of a date can be used as the tag's value. See below for date input formats. |
valid day |
Indicates the days of the week that are allowed to be selected within the calendar control. If the date is entered manually, the system will check the date to make sure the date entered is on a valid day. The tag value is a non-delimited list of the numeric day value for the days that are valid to be shown in the calendar control. '0' = Sunday; '1' = Monday; '2' = Tuesday; '3' = Wednesday; '4' = Thursday; '5' = Friday; '6' = Saturday For example, if you wanted to show only Monday through Friday, the tag value would be |
datatype |
Validates the date format that can be entered into the
If not specified, the |
first day |
Specifies which day of the week the calendar begins on; '0' = Sunday (default), '1' = Monday, etc. |
Date input formats
There are several formats that default date
, start date
, and end date
accept. Here are some examples:
-
0
= today,-3
= three days ago,+4
= four days from today -
"+2m -3d"
= just shy of two months from now (for use withstart date
anddefault date
only) -
11/20/2020
= explicitly defined dates work, too.
Examples
Establishing a default date
In the following example, the default date
tag is set. When the calendar pops up, that date is shown as the initially displayed date.
Establishing date thresholds
'start date'
Users may set an earliest or latest possible date that can be entered/selected by applying the start date
and end date
tags, respectively. In Q2, the start date
tag is set to '05/27/2023' (the start of Memorial Day weekend in 2023). When the calendar control pops up, any dates prior to May 27th, 2023 are grayed out and disabled. These dates cannot be selected, and if typed into the date text field, will lead to a validation error, prompting the respondent to enter another date.
'end date'
In Q3 the end date
tag is set to '10/30/2023'. When the calendar control pops up, the calendar will default to highlighting the current date. Any dates after October 30th, 2023 are grayed out and disabled.
If need be, both a start date and end date could be specified in the same question (e.g., for seasonal businesses), and any dates outside of this range will be unable to be selected or accepted.
Limiting days of the week
The valid day
tag is used to specify which days of the week are permissible in a date response. This tag may accept a group of numbers together to indicate which days may be selected. Since each day of the week corresponds to a single digit — '0' = Sunday,'1' = Monday, ... '6' = Saturday — specifying '0456' implies that only the 0, 4, 5, & 6 days may be selected (Sunday, Thursday, Friday, and Saturday). Any days' numbers that are unlisted will be disabled within the calendar control and cannot be entered manually into the text field.
Altering the start of the calendar week
Use the first day
tag to specify the first day of the calendar week, '0' for Sunday (default) or '1' for Monday. In this example, specifying firstday: 1
shifts the calendar such that the weeks are displayed Monday through Sunday instead of the more traditional/default Sunday through Saturday.
Specifying date format
The datatype
tag may be applied to alter the date format. Here, it is set to the 'ddmmyy' format. Note that this does not affect the format of the response stored in the survey data, which is always "YYYY-MM-DD". To store the date in an alternate format, see Referencing a 'type: date' question below.
When a date is selected using the calendar control, it will properly format the date to match the formatting datatype that was selected, or entered into the date
text box.
Within the past month
It is possible to specify that, no matter the date on which a survey is taken, all dates displayed will be within the last X number of months or days from the current date by using the start date
tag and subtracting from that date. For example, in order to make sure the only dates displayed for selection are within the past month, use start date: "-1m"
; if it is desired to be within the past week, one could use start date: "-7d"
or start date: "-7"
.
The end date: 0
tag makes the current date the final date shown/allowed.
Referencing a 'type: date' question
Date questions store the data in the format "YYYY-MM-DD". If you need to display the selected date later in the survey, it will display in that format. As an alternative, the response to a date question can be stored in a text variable in a different format, which you can then reference instead of the original date question. To do this, use the following syntax at the cvalue
in Q9TEXT below.
Use today's date as the start or end date
To prevent the selection of a date before (or after) the current date at the time the respondent takes the survey, use start date: 0
or end date: 0
, respectively.
Comments
0 comments
Please sign in to leave a comment.