You are here

function webform_date_string in Webform 7.4

Same name and namespace in other branches
  1. 6.3 webform.module \webform_date_string()
  2. 7.3 webform.module \webform_date_string()

Convert an array of a date or time into an ISO 8601 compatible string.

Parameters

$array: The array to convert to a date or time string.

$type: If wanting a specific string format back specify either "date" or "time". Otherwise a full ISO 8601 date and time string will be returned.

Return value

string Date in string format

4 calls to webform_date_string()
webform_conditional_value_datetime in includes/webform.conditionals.inc
Utility function to convert incoming time and dates into strings.
webform_expand_time in components/time.inc
Form API #process function for Webform time fields.
_webform_submit_date in components/date.inc
Implements _webform_submit_component().
_webform_submit_time in components/time.inc
Implements _webform_submit_component().

File

./webform.module, line 5146
This module provides a simple way to create forms and questionnaires.

Code

function webform_date_string($array, $type = NULL) {
  $string = '';
  if ($type == 'date' || !isset($type)) {
    $string .= empty($array['year']) ? '0000' : sprintf('%04d', $array['year']);
    $string .= '-';
    $string .= empty($array['month']) ? '00' : sprintf('%02d', $array['month']);
    $string .= '-';
    $string .= empty($array['day']) ? '00' : sprintf('%02d', $array['day']);
  }
  if (!isset($type)) {
    $string .= 'T';
  }
  if ($type == 'time' || !isset($type)) {
    $string .= empty($array['hour']) ? '00' : sprintf('%02d', $array['hour']);
    $string .= ':';
    $string .= empty($array['minute']) ? '00' : sprintf('%02d', $array['minute']);
    $string .= ':';
    $string .= empty($array['second']) ? '00' : sprintf('%02d', $array['second']);
  }
  return $string;
}