Skip to main content

Extracting an element of a date

Explains the date format operation

Lorraine avatar
Written by Lorraine
Updated over a week ago

The Date format in the questionnaire is set by default to be short form (e.g. 01/10/2021). However on some occasions, you might want to extract a specific element of the date. For example, the day, month or year.

In the example below, the specific month of February has been extracted from the answered date.

For added help feel free to watch this video:

  1. To start off, navigate to the Operations tab in your template. To start off, navigate to the Operations tab in your template. Then, click the blue + button.

2. A pop up menu will appear on the right. Rename your operation to your desired name and click "Rename operation".

3. To create the operation, click the "Add" button and select Date Format under Localisation, so that Date Format is in the top band.

4. Then click the word "Add" again and select the term Attribute. In the drop down list for the attribute, you can either select an existing Date attribute. Or, you can create a wholly new attribute.

Finally select the locale (that will dictate the language used for your operation), if you skip this part it will default to English . You can do this by adding a "Text" argument and adding the relevant locale code, for example, the locale code for English is "en_GB" (other commonly used ones include "es" for Spanish, "fr" for French, "de" for German and "pt" for Portuguese). If you want to see more locales, you can check our operations guide here.

5. Then, go back into the questionnaire and navigate to the relevant attribute. Click the drop down list to the right of the attribute and change the question type to Date.

6. Then, choose the element of the date that you wish to extract. This is inputted by selecting the text input and typing in the relevant date format code.

Note that a comprehensive list of date format codes can be found by going to page 54 of Avvoka's Operations Guide, here. Below you can see some of the commonly used date format codes:

Common Date format codes

Year

Full year

%Y

2000, 2001, 2019

Short year with zero padding

%y

01, 02, 19

Month

Full month name

%B

January, February, March

Month number with zero padding

%m

01, 02, 03

Day

Day of the month with zero padding

%d

01, 02, …, 31

Day of the month without zero padding

%-d

1, 2, …, 31

7. After this, navigate back to the "Document" tab. Navigate to the Automation tab on the blue bar on the top and click the Operations icon. Select the relevant operation and click insert.

8. Your operation should now work! Click on the "Live Demo" to test it out by answering the relevant date question.

Did this answer your question?