mixed convertDateTime(mixed dateTime, [string formatDateTime], [string formatOutput])
The function convertDateTime()
converts a date or a timestamp into a different date or timestamp.
1418045461
) or a string describing a date and/or a time (e.g. 8.12.2014 14:31
'). nil
– automatically renders the dateTime, as long as the usual date and time notation follows. For example, “1.4.”, “4/1/2014”, “16:30”, “1.4.2014 16:30”. DateTime::createFromFormat()
(e.g. 'd.m.Y H:i
') nil
– returns a Unix timestamp.date()
(z.B. 'd.m.Y H:i
').In the text input “AB01_01”, the respondent was asked to give the date and time of when he last watched television. The information should be specified as “hour:minute” (for the current day) or “day.month hour:minute” for previous days.
The following PHP code is put at the very top on the page after question “AB01”. If the input cannot be recognized as a valid date/time, the text element “date error” is displayed the and the question shown again using repeatPage()
if (convertDateTime(value('AB01_01')) == false) { text('dateerror'); repeatPage(); }
Further back in the questionnaire this date should now be displayed in the standardized format “day.month.year hour:minute”. The placeholder %date% is used in a question in order to display this. The following PHP code is put above the question (or may already be above).
$input = value('AB01_01'); $output = convertDateTime($input, nil, 'd.m.Y H:i'); replace('%date%', $output);