Skip to main content

FV Kinesis Support

All the topics, resources needed for FV Kinesis.

FocusVision Knowledge Base

Date and Time Examples

1:  Translating Date questions

Our Date question type provides support for localizing its content to cater for different languages. Each localization is contained within its own file with the language code appended to the name, e.g., jquery.ui.datepicker-fr.js for French.

The $.datepicker.regional attribute holds an array of localizations, indexed by language code, with "" referring to the default (English). Each entry is an object with the following attributes: closeText, prevText, nextText, currentText, monthNames, monthNamesShort, dayNames, dayNamesShort, dayNamesMin, weekHeader, dateFormat, firstDay, isRTL, showMonthAfterYear, and yearSuffix.

You can restore the default localizations with: $.datepicker.setDefaults( $.datepicker.regional[ "" ] );

And can then override an individual datepicker for a specific locale: $( selector ).datepicker( $.datepicker.regional[ "fr" ] );

Below you will find the paths for each supported language. You can include these in the surrounding HTML for your Date question. See example below:

<script type="text/javascript" src="https://www.yourdomain.com/yourinstall/jquery/ui-1.8.2-custom/development-bundle/ui/i18n/jquery.ui.datepicker-es.js">

<script>
$(document).ready(function(){
       $("#Q6").datepicker("option", $.datepicker.regional["es"]);
});
</script>

Available languages and landcodes are listed below (make sure to use full URL path as shown in example above):

/jquery.ui.datepicker-af.js
/jquery.ui.datepicker-ar-DZ.js
/jquery.ui.datepicker-ar.js
/jquery.ui.datepicker-az.js
/jquery.ui.datepicker-be.js
/jquery.ui.datepicker-bg.js
/jquery.ui.datepicker-bs.js
/jquery.ui.datepicker-ca.js
/jquery.ui.datepicker-cs.js
/jquery.ui.datepicker-cy-GB.js
/jquery.ui.datepicker-da.js
/jquery.ui.datepicker-de.js
/jquery.ui.datepicker-el.js
/jquery.ui.datepicker-en-AU.js
/jquery.ui.datepicker-en-GB.js
/jquery.ui.datepicker-en-NZ.js
/jquery.ui.datepicker-eo.js
/jquery.ui.datepicker-es.js
/jquery.ui.datepicker-et.js
/jquery.ui.datepicker-eu.js
/jquery.ui.datepicker-fa.js
/jquery.ui.datepicker-fi.js
/jquery.ui.datepicker-fo.js
/jquery.ui.datepicker-fr-CA.js
/jquery.ui.datepicker-fr-CH.js
/jquery.ui.datepicker-fr.js
/jquery.ui.datepicker-gl.js
/jquery.ui.datepicker-he.js
/jquery.ui.datepicker-hi.js
/jquery.ui.datepicker-hr.js
/jquery.ui.datepicker-hu.js
/jquery.ui.datepicker-hy.js
/jquery.ui.datepicker-id.js
/jquery.ui.datepicker-is.js
/jquery.ui.datepicker-it.js
/jquery.ui.datepicker-ja.js
/jquery.ui.datepicker-ka.js
/jquery.ui.datepicker-kk.js
/jquery.ui.datepicker-km.js
/jquery.ui.datepicker-ko.js
/jquery.ui.datepicker-ky.js
/jquery.ui.datepicker-lb.js
/jquery.ui.datepicker-lt.js
/jquery.ui.datepicker-lv.js
/jquery.ui.datepicker-mk.js
/jquery.ui.datepicker-ml.js
/jquery.ui.datepicker-ms.js
/jquery.ui.datepicker-nb.js
/jquery.ui.datepicker-nl-BE.js
/jquery.ui.datepicker-nl.js
/jquery.ui.datepicker-nn.js
/jquery.ui.datepicker-no.js
/jquery.ui.datepicker-pl.js
/jquery.ui.datepicker-pt-BR.js
/jquery.ui.datepicker-pt.js
/jquery.ui.datepicker-rm.js
/jquery.ui.datepicker-ro.js
/jquery.ui.datepicker-ru.js
/jquery.ui.datepicker-sk.js
/jquery.ui.datepicker-sl.js
/jquery.ui.datepicker-sq.js
/jquery.ui.datepicker-sr-SR.js
/jquery.ui.datepicker-sr.js
/jquery.ui.datepicker-sv.js
/jquery.ui.datepicker-ta.js
/jquery.ui.datepicker-th.js
/jquery.ui.datepicker-tj.js
/jquery.ui.datepicker-tr.js
/jquery.ui.datepicker-uk.js
/jquery.ui.datepicker-vi.js
/jquery.ui.datepicker-zh-CN.js
/jquery.ui.datepicker-zh-HK.js
/jquery.ui.datepicker-zh-TW.js

2:  Calculating Age From Date of Birth

Recording a respondents age is very simple but the logic depends on the question type being used to record the date of birth. The following code is the basic template based on using a separate open end for the month, day, and year. The first 3 lines will need to be updated to reflect the question labels within your particular survey.

VIEW DEMO

$USER_month = $Qmonth;
$USER_day = $Qday;
$USER_year = $Qyear;

$USER_year_diff = date("Y") - $USER_year;
$USER_month_diff = date("m") - $USER_month;
$USER_day_diff = date("d") - $USER_day;

if ($USER_month_diff < 0) $USER_year_diff--;
elseif (($USER_month_diff==0) && ($USER_day_diff < 0)) $USER_year_diff--;
return $USER_year_diff;

2.1:  From Date Question

When using the Kinesis Date question type, the first 3 lines will need to be altered. You will need to reference the date question label and field order in brackets (starting from 0). The first 3 lines would be written like this:

$USER_year = $Qdob[0];
$USER_month = $Qdob[1];
$USER_day = $Qdob[2];

Please note that, regardless of the date format, the year gets stored in the first field [0] of the date question, the month in the second [1] and the day in the third [2].

2.2:  From Pulldown Question

When using a question such as a pulldown, these first 3 lines would need to be altered because pulldowns record the choice id and not the choice text. So the month and day part would not need to change. For example, "January" as the first month choice would already correspond to the value of "1", and the same for day choice of 20 would match the value "20". Most often the year will be recorded from a range of years, such as 1900-2000. In this case the first option choice of 1900 would have a value of 1, and would throw off the code. So we would need to add a number to the value that will get the same number as the choice text. So 1+1899 = 1900, 2+1899 = 1901 and so on.

$USER_month = $Qmonth;
$USER_day = $Qday;
$USER_year = $Qyear+1899;

3:  Return Difference Between Dates

This example will calculate the difference between two date questions. Create both date questions - Qstart and Qend. Next, create a number question with the logic below for the default answer condition:

VIEW DEMO

$USER_days = (strtotime("$Qend[0]-$Qend[1]-$Qend[2]") - strtotime("$Qstart[0]-$Qstart[1]-$Qstart[2]")) / (86400);
return $USER_days;

The above code subtracts start time from end time, then divides by 86400 (one day in seconds). Dates are always stored in data with format YYYY-MM-DD, regardless of input mask.

4:  Disabling the DatePicker popup

Use the following javascript example to disable the default popup calendar for  Date Questions. Note this script call must be on the same screen as the date question to work, after the date question. In the syntax below, the datapoint for your date question is represented by QDOB.

    <script type="text/Javascript">
    $(document).ready(function(){
           $('#QDOB').datepicker("destroy").unbind('click');
    });
    </script>
  • Was this article helpful?