symfony API

DateFormHelper Functions

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to API menu

1.2 API OpenSearch

Packages

You are currently browsing the symfony API for the 1.2 version. Switch to:
This version of symfony is not maintained anymore.
If some of your projects still use this version, consider upgrading as soon as possible.

DateFormHelper.

Function Summary

  • string select_ampm_tag($name, $value = null, $options = array(), $html_options = array())
    Returns a <select> tag populated with AM and PM options for use with 12-Hour time.
  • string select_datetime_tag($name, $value = null, $options = array(), $html_options = array())
    Returns a variable number of <select> tags populated with date and time related select boxes.
  • string select_date_tag($name, $value = null, $options = array(), $html_options = array())
    Returns three <select> tags populated with a range of months, days, and years.
  • string select_day_tag($name, $value = null, $options = array(), $html_options = array())
    Returns a <select> tag populated with all the days of the month (1 - 31).
  • string select_hour_tag($name, $value = null, $options = array(), $html_options = array())
    Returns a <select> tag populated with 24 hours (0 - 23), or optionally 12 hours (1 - 12).
  • string select_minute_tag($name, $value = null, $options = array(), $html_options = array())
    Returns a <select> tag populated with 60 minutes (0 - 59).
  • string select_month_tag($name, $value = null, $options = array(), $html_options = array())
    Returns a <select> tag populated with all the months of the year (1 - 12).
  • string select_number_tag($name, $value, $options = array(), $html_options = array())
    Returns a <select> tag, populated with a range of numbers
  • string select_second_tag($name, $value = null, $options = array(), $html_options = array())
    Returns a <select> tag populated with 60 seconds (0 - 59).
  • string select_timezone_tag($name, $selected = null, $options = array())
    Returns a <select> tag populated with all the timezones in the world.
  • string select_time_tag($name, $value = null, $options = array(), $html_options = array())
    Returns three <select> tags populated with hours, minutes, and optionally seconds.
  • string select_year_tag($name, $value = null, $options = array(), $html_options = array())
    Returns a <select> tag populated with a range of years.
  • string _get_I18n_date_locales($culture = null)
    Retrieves the proper date format based on the specified setting
  • string _parse_value_for_date($value, $key, $format_char)
    Converts date values () into its correct date format ()

Function Details

  • (string) select_ampm_tag ($name, $value = null, $options = array(), $html_options = array()) Browse code

    $name field name
    $value selected value (AM or PM)
    $options special options for the select tag
    $html_options additional HTML compliant <select> tag parameters

    Returns a &lt;select&gt; tag populated with AM and PM options for use with 12-Hour time.


    By default, the $value parameter is set to the correct AM/PM setting based on the current time. To override this, simply pass either AM or PM to the $value parameter. You can also set the $value parameter to null which will disable the $value, however this will only be useful if you pass 'include_blank' or 'include_custom' to the $options parameter. For convenience, Symfony also offers the select_time_tag select_datetime_tag helper functions which combine other date and time helpers to easily build date and time select boxes.

    Options:


    • include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.

    • include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.



    Examples:
      echo select_ampm_tag('ampm');

      echo select_ampm_tag('ampm', 'PM', array('include_blank' => true));

    returns <select> tag populated with AM and PM options for use with 12-Hour time.

  • (string) select_datetime_tag ($name, $value = null, $options = array(), $html_options = array()) Browse code

    $name field name (automatically becomes an array of date and time parts)
    $value accepts a valid time string or properly formatted time array
    $options special options for the select tagss
    $html_options additional HTML compliant <select> tag parameters

    Returns a variable number of &lt;select&gt; tags populated with date and time related select boxes.


    The select_datetime_tag is the culmination of both the select_date_tag and the select_time_tag. By default, the $value parameter is set to the current date and time. To override this, simply pass a valid date, time, datetime string or correctly formatted array (see example) to the $value parameter. You can also set the $value parameter to null which will disable the $value, however this will only be useful if you pass 'include_blank' or 'include_custom' to the $options parameter. To include seconds to the result, use set the 'include_second' option in the $options parameter to true. Note: The $name parameter will automatically converted to array names. For example, a $name of "datetime" becomes: <select name="datetime[month]">...</select>
    <select name="datetime[day]">...</select>
    <select name="datetime[year]">...</select>
    <select name="datetime[hour]">...</select>
    <select name="datetime[minute]">...</select>
    <select name="datetime[second]">...</select>

    Options:


    • include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.

    • include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.

    • include_second - If set to true, includes the "seconds" select tag as part of the result.

    • discard_month - If set to true, will only return select tags for day and year.

    • discard_day - If set to true, will only return select tags for month and year.

    • discard_year - If set to true, will only return select tags for month and day.

    • use_month_numbers - If set to true, will show the month's numerical value (1 - 12) instead of the months full name.

    • use_short_month - If set to true, will show the month's short name (i.e. Jan, Feb, Mar) instead of its full name.

    • year_start - If set, the range of years will begin at this four-digit date (i.e. 1979)

    • year_end - If set, the range of years will end at this four-digit date (i.e. 2025)

    • second_step - If set, the seconds will be incremented in blocks of X, where X = 'second_step'

    • minute_step - If set, the minutes will be incremented in blocks of X, where X = 'minute_step'

    • 12hour_time - If set to true, will return integers 1 through 12 instead of the default 0 through 23.

    • date_seperator - Includes a string of defined text between each generated select tag

    • time_seperator - Includes a string of defined text between each generated select tag

    • ampm_seperator - Includes a string of defined text between the minute/second select box and the AM/PM select box



    Examples:
      echo select_datetime_tag('datetime');

      echo select_datetime_tag('datetime', '1979-10-30');

      $datetime = array('year' => '1979', 'month' => 10, 'day' => 30, 'hour' => '15', 'minute' => 46);
    
    echo select_datetime_tag('time', $datetime, array('use_short_month' => true, '12hour_time' => true));

    returns a variable number of <select> tags populated with date and time related select boxes

  • (string) select_date_tag ($name, $value = null, $options = array(), $html_options = array()) Browse code

    $name field name (automatically becomes an array of parts: name[year], name[month], year[day])
    $value accepts a valid date string or properly formatted date array
    $options special options for the select tags
    $html_options additional HTML compliant <select> tag parameters

    Returns three &lt;select&gt; tags populated with a range of months, days, and years.


    By default, the $value parameter is set to today's month, day and year. To override this, simply pass a valid date or a correctly formatted date array (see example) to the $value parameter. You can also set the $value parameter to null which will disable the $value, however this will only be useful if you pass 'include_blank' or 'include_custom' to the $options parameter. Also, the default selectable range of years is set to show five years back and five years forward from today's year. For instance, if today's year is 2006, the default 'year_start' option will be set to 2001 and the 'year_end' option will be set to 2011. These start and end dates can easily be overwritten by setting the 'year_start' and 'year_end' options in the $options parameter.

    Note: The $name parameter will automatically converted to array names. For example, a $name of "date" becomes: <select name="date[month]">...</select>
    <select name="date[day]">...</select>
    <select name="date[year]">...</select>

    Options:


    • include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.

    • include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.

    • discard_month - If set to true, will only return select tags for day and year.

    • discard_day - If set to true, will only return select tags for month and year.

    • discard_year - If set to true, will only return select tags for month and day.

    • use_month_numbers - If set to true, will show the month's numerical value (1 - 12) instead of the months full name.

    • use_short_month - If set to true, will show the month's short name (i.e. Jan, Feb, Mar) instead of its full name.

    • year_start - If set, the range of years will begin at this four-digit date (i.e. 1979)

    • year_end - If set, the range of years will end at this four-digit date (i.e. 2025)

    • date_seperator - Includes a string of defined text between each generated select tag



    Examples:
      echo select_date_tag('date');

      echo select_date_tag('date', '2006-10-30');

      $date = array('year' => '1979', 'month' => 10, 'day' => 30);
    
    echo select_date_tag('date', $date, array('year_start' => $date['year'] - 10, 'year_end' => $date['year'] + 10));

    returns three <select> tags populated with a months, days and years

  • (string) select_day_tag ($name, $value = null, $options = array(), $html_options = array()) Browse code

    $name field name
    $value selected value (1 - 31)
    $options special options for the select tag
    $html_options additional HTML compliant <select> tag parameters

    Returns a &lt;select&gt; tag populated with all the days of the month (1 - 31).


    By default, the $value parameter is set to today's day. To override this, simply pass an integer (1 - 31) to the $value parameter. You can also set the $value parameter to null which will disable the $value, however this will only be useful if you pass 'include_blank' or 'include_custom' to the $options parameter. For convenience, symfony also offers the select_date_tag helper function which combines the select_year_tag, select_month_tag, and select_day_tag functions into a single helper.

    Options:


    • include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.

    • include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.



    Examples:
      echo select_day_tag('day', 14);

    returns <select> tag populated with all the days of the month (1 - 31).

  • (string) select_hour_tag ($name, $value = null, $options = array(), $html_options = array()) Browse code

    $name field name
    $value selected value (0 - 23 or 1 - 12 if '12hour_time' = true)
    $options special options for the select tag
    $html_options additional HTML compliant <select> tag parameters

    Returns a &lt;select&gt; tag populated with 24 hours (0 - 23), or optionally 12 hours (1 - 12).


    By default, the $value parameter is set to the current hour. To override this, simply pass an integer (0 - 23 or 1 - 12 if '12hour_time' = true) to the $value parameter. You can also set the $value parameter to null which will disable the $value, however this will only be useful if you pass 'include_blank' or 'include_custom' to the $options parameter. For convenience, Symfony also offers the select_time_tag select_datetime_tag helper functions which combine other date and time helpers to easily build date and time select boxes.

    Options:


    • include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.

    • include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.

    • 12hour_time - If set to true, will return integers 1 through 12 instead of the default 0 through 23 as well as an AM/PM select box.



    Examples:
      echo select_hour_tag('hour');

      echo select_hour_tag('hour', 6, array('12hour_time' => true));

    returns <select> tag populated with 24 hours (0 - 23), or optionally 12 hours (1 - 12).

  • (string) select_minute_tag ($name, $value = null, $options = array(), $html_options = array()) Browse code

    $name field name
    $value selected value (0 - 59)
    $options special options for the select tag
    $html_options additional HTML compliant <select> tag parameters

    Returns a &lt;select&gt; tag populated with 60 minutes (0 - 59).


    By default, the $value parameter is set to the current minute. To override this, simply pass an integer (0 - 59) to the $value parameter. You can also set the $value parameter to null which will disable the $value, however this will only be useful if you pass 'include_blank' or 'include_custom' to the $options parameter. In many cases, you have no need for all 60 minutes in an hour. the 'minute_step' option in the $options parameter gives you the ability to define intervals to display. So for instance you could define 15 as your 'minute_step' interval and the select tag would return the values 0, 15, 30, and 45. For convenience, Symfony also offers the select_time_tag select_datetime_tag helper functions which combine other date and time helpers to easily build date and time select boxes.

    Options:


    • include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.

    • include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.

    • minute_step - If set, the minutes will be incremented in blocks of X, where X = 'minute_step'



    Examples:
      echo select_minute_tag('minute');

      echo select_minute_tag('minute', 15, array('minute_step' => 15));

    returns <select> tag populated with 60 minutes (0 - 59).

  • (string) select_month_tag ($name, $value = null, $options = array(), $html_options = array()) Browse code

    $name field name
    $value selected value (1 - 12)
    $options special options for the select tag
    $html_options additional HTML compliant <select> tag parameters

    Returns a &lt;select&gt; tag populated with all the months of the year (1 - 12).


    By default, the $value parameter is set to today's month. To override this, simply pass an integer (1 - 12) to the $value parameter. You can also set the $value parameter to null which will disable the $value, however this will only be useful if you pass 'include_blank' or 'include_custom' to the $options parameter. Also, the each month's display title is set to return its respective full month name, which can be easily overridden by passing the 'use_short_names' or 'use_month_numbers' options to the $options parameter. For convenience, Symfony also offers the select_date_tag helper function which combines the select_year_tag, select_month_tag, and select_day_tag functions into a single helper.

    Options:


    • include_blank - Includes a blank <option> tag at the beginning of the string with an empty value

    • include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value

    • use_month_numbers - If set to true, will show the month's numerical value (1 - 12) instead of the months full name.

    • use_short_month - If set to true, will show the month's short name (i.e. Jan, Feb, Mar) instead of its full name.



    Examples:
      echo select_month_tag('month', 5, array('use_short_month' => true));

      echo select_month_tag('month', null, array('use_month_numbers' => true, 'include_blank' => true));

    returns <select> tag populated with all the months of the year (1 - 12).

  • (string) select_number_tag ($name, $value, $options = array(), $html_options = array()) Browse code

    $name field name
    $value the selected option
    $options special options for the select tagss
    $html_options additional HTML compliant <select> tag parameters

    Returns a &lt;select&gt; tag, populated with a range of numbers


    By default, the select_number_tag generates a list of numbers from 1 - 10, with an incremental value of 1. These values can be easily changed by passing one or several $options. Numbers can be either positive or negative, integers or decimals, and can be incremented by any number, decimal or integer. If you require the range of numbers to be listed in descending order, pass the 'reverse' option to easily display the list of numbers in the opposite direction.

    Options:


    • include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.

    • include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.

    • multiple - If set to true, the select tag will allow multiple numbers to be selected at once.

    • start - The first number in the list. If not specified, the default value is 1.

    • end - The last number in the list. If not specified, the default value is 10.

    • increment - The number by which to increase each number in the list by until the number is greater than or equal to the 'end' option.
      If not specified, the default value is 1.

    • reverse - Reverses the order of numbers so they are display in descending order



    Examples:
      echo select_number_tag('rating', '', array('reverse' => true));

      echo echo select_number_tag('tax_rate', '0.07', array('start' => '0.05', 'end' => '0.09', 'increment' => '0.01'));

      echo select_number_tag('limit', 5, array('start' => 5, 'end' => 120, 'increment' => 15));

    returns <select> tag populated with a range of numbers.

  • (string) select_second_tag ($name, $value = null, $options = array(), $html_options = array()) Browse code

    $name field name
    $value selected value (0 - 59)
    $options special options for the select tag
    $html_options additional HTML compliant <select> tag parameters

    Returns a &lt;select&gt; tag populated with 60 seconds (0 - 59).


    By default, the $value parameter is set to the current second (right now). To override this, simply pass an integer (0 - 59) to the $value parameter. You can also set the $value parameter to null which will disable the $value, however this will only be useful if you pass 'include_blank' or 'include_custom' to the $options parameter. In many cases, you have no need for all 60 seconds in a minute. the 'second_step' option in the $options parameter gives you the ability to define intervals to display. So for instance you could define 15 as your 'minute_step' interval and the select tag would return the values 0, 15, 30, and 45. For convenience, Symfony also offers the select_time_tag select_datetime_tag helper functions which combine other date and time helpers to easily build date and time select boxes.

    Options:


    • include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.

    • include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.

    • second_step - If set, the seconds will be incremented in blocks of X, where X = 'second_step'



    Examples:
      echo select_second_tag('second');

      echo select_second_tag('second', 15, array('second_step' => 15));

    returns <select> tag populated with 60 seconds (0 - 59).

  • (string) select_timezone_tag ($name, $selected = null, $options = array()) Browse code

    $name field name
    $selected selected field value (timezone identifier)
    $options additional HTML compliant <select> tag parameters

    Returns a &lt;select&gt; tag populated with all the timezones in the world.


    The select_timezone_tag builds off the traditional select_tag function, and is conveniently populated with all the timezones in the world (sorted alphabetically). Each option in the list has a unique timezone identifier for its value and the timezone's locale as its display title. The timezone data is retrieved via the sfCultureInfo class, which stores a wide variety of i18n and i10n settings for various countries and cultures throughout the world. Here's an example of an <option> tag generated by the select_timezone_tag:

    Options:


    • display -
      identifer - Display the PHP timezone identifier (e.g. America/Denver)
      timezone - Display the full timezone name (e.g. Mountain Standard Time)
      timezone_abbr - Display the timezone abbreviation (e.g. MST)
      timzone_dst - Display the full timezone name with daylight savings time (e.g. Mountain Daylight Time)
      timezone_dst_abbr - Display the timezone abbreviation with daylight savings time (e.g. MDT)
      city - Display the city/region that relates to the timezone (e.g. Denver)



    <option value="America/Denver">America/Denver</option>

    Examples:

      echo select_timezone_tag('timezone', 'America/Denver');

    returns <select> tag populated with all the timezones in the world.

  • (string) select_time_tag ($name, $value = null, $options = array(), $html_options = array()) Browse code

    $name field name (automatically becomes an array of parts: name[hour], name[minute], year[second])
    $value accepts a valid time string or properly formatted time array
    $options special options for the select tag
    $html_options additional HTML compliant <select> tag parameters

    Returns three &lt;select&gt; tags populated with hours, minutes, and optionally seconds.


    By default, the $value parameter is set to the current hour and minute. To override this, simply pass a valid time or a correctly formatted time array (see example) to the $value parameter. You can also set the $value parameter to null which will disable the $value, however this will only be useful if you pass 'include_blank' or 'include_custom' to the $options parameter. To include seconds to the result, use set the 'include_second' option in the $options parameter to true. Note: The $name parameter will automatically converted to array names. For example, a $name of "time" becomes: <select name="time[hour]">...</select>
    <select name="time[minute]">...</select>
    <select name="time[second]">...</select>

    Options:


    • include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.

    • include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.

    • include_second - If set to true, includes the "seconds" select tag as part of the result.

    • second_step - If set, the seconds will be incremented in blocks of X, where X = 'second_step'

    • minute_step - If set, the minutes will be incremented in blocks of X, where X = 'minute_step'

    • 12hour_time - If set to true, will return integers 1 through 12 instead of the default 0 through 23 as well as an AM/PM select box.

    • time_seperator - Includes a string of defined text between each generated select tag

    • ampm_seperator - Includes a string of defined text between the minute/second select box and the AM/PM select box



    Examples:
      echo select_time_tag('time');

      echo select_time_tag('date', '09:31');

      $time = array('hour' => '15', 'minute' => 46, 'second' => 01);
    
    echo select_time_tag('time', $time, array('include_second' => true, '12hour_time' => true));

    returns three <select> tags populated with a hours, minutes and optionally seconds.

  • (string) select_year_tag ($name, $value = null, $options = array(), $html_options = array()) Browse code

    $name field name
    $value selected value within the range of years.
    $options special options for the select tag
    $html_options additional HTML compliant <select> tag parameters

    Returns a &lt;select&gt; tag populated with a range of years.


    By default, the $value parameter is set to today's year. To override this, simply pass a four-digit integer (YYYY) to the $value parameter. You can also set the $value parameter to null which will disable the $value, however this will only be useful if you pass 'include_blank' or 'include_custom' to the $options parameter. Also, the default selectable range of years is set to show five years back and five years forward from today's year. For instance, if today's year is 2006, the default 'year_start' option will be set to 2001 and the 'year_end' option will be set to 2011. These start and end dates can easily be overwritten by setting the 'year_start' and 'year_end' options in the $options parameter. For convenience, Symfony also offers the select_date_tag helper function which combines the select_year_tag, select_month_tag, and select_day_tag functions into a single helper.

    Options:


    • include_blank - Includes a blank <option> tag at the beginning of the string with an empty value

    • include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value

    • year_start - If set, the range of years will begin at this four-digit date (i.e. 1979)

    • year_end - If set, the range of years will end at this four-digit date (i.e. 2025)



    Examples:
      echo select_year_tag('year');

      $year_start = date('Y', strtotime('-10 years'));
    
    $year_end = date('Y', strtotime('+10 years'));
    echo select_year_tag('year', null, array('year_start' => $year_start, 'year_end' => $year_end));

    returns <select> tag populated with a range of years.

  • (string) _get_I18n_date_locales ($culture = null) Browse code

    $culture two or three character culture setting variable

    Retrieves the proper date format based on the specified setting


    Note: If no $culture is defined, the user's culture setting will be used in its place.

    returns formatted date/time format based on the specified date/time setting

  • (string) _parse_value_for_date ($value, $key, $format_char) Browse code

    $value date or date part
    $key custom key for array values
    $format_char date format

    Converts date values () into its correct date format ()


    This function is primarily used in select_date_tag, select_time_tag and select_datetime_tag.

    Note: If $value is empty, it will be populated with the current date and time.

    returns properly formatted date part value.