Calculating the number of days between two dates
This worksheet shows how to calculate the number of days between two dates. The example used is for a questionnaire asking about a participant’s vacation where the period of time the participant spent on vacation is calculated. Additionally, there is an analysis requirement to determine the average length of vacation by age of respondent and to group the vacations into length of vacation bands.
The questionnaire needs to ask for the date when the participants went on vacation, the date they returned and their age in order to calculate the analysis requirements.
Create a variable for the number of days away
- Enter two open ended, date response questions, one for the vacation departure date and one for the vacation return date. Then create Q3 using a multiple-choice, single response question to capture respondent’s ages. The questions are shown here.
- From the Variables window click New Variable to create the variable that will contain the formula to work out the number of days between the two dates
- Enter the following information:
- Name: DaysAway
- Label: Days Away on Vacation
- Type: Derived
- Response: Quantity
- Text: Days Away on Vacation
- In the Values column, in the same row as Valid, type Q2-Q1. This will calculate the number of days between holiday departure date and holiday return date.
Create a table showing the average length of stay by age
- Click on Analysis Table . This opens the Analysis Definition dialog.
- In Analysis, enter Q3 What is your age?
- In the Calculate dropdown select Means and Significances and in the box to the right enter the derived variable, DaysAway.
- Click OK to show results.
Grouping the number of days on vacation into bands
This will categorise the data so that a table or chart can be produced.
- From the Variables window click New Variable to create the variable to show the amount of days from the departure date to the return date.
- Enter the following information:
- Name: Length
- Label: Length of Vacation
- Type: Derived
- Response: Single
- In the Code list, click the Label field for Code 1 and enter 1 to 3 days. Press Tab on the keyboard, to move to the Values column. In this column Snap needs to know what numbers are to be displayed in this answer, enter 1 to 3. Follow the same procedure to create categories for 4 to 6 days, 7 to 10 days and over 10 days.
- Click on Toggle Definitions and change Calculation to DaysAway.
- Click Save to save.
- Click on Analysis Table to show the Analysis Definition window.
- In Analysis enter Length. Click OK to show results.
If there is a topic you would like a worksheet on, email to snapideas@snapsurveys.com