Skip to content

{html_select_time}

{html_select_time} is a custom function that creates time dropdowns for you. It can display any or all of: hour, minute, second and meridian.

The time attribute can have different formats. It can be a unique timestamp, a string of the format YYYYMMDDHHMMSS or a string that is parseable by PHP's strtotime().

Attributes

Attribute Name Default Description
prefix Time_ What to prefix the var name with
time current timestamp What date/time to pre-select. Accepts timestamp, DateTime, mysql timestamp or any string parsable by strtotime(). If an array is given, the attributes field_array and prefix are used to identify the array elements to extract hour, minute, second and meridian from.
display_hours TRUE Whether or not to display hours
display_minutes TRUE Whether or not to display minutes
display_seconds TRUE Whether or not to display seconds
display_meridian TRUE Whether or not to display meridian (am/pm)
use_24_hours TRUE Whether or not to use 24 hour clock
minute_interval 1 Number interval in minute dropdown
second_interval 1 Number interval in second dropdown
hour_format \%02d What format the hour label should be in (sprintf)
hour_value_format \%20d What format the hour value should be in (sprintf)
minute_format \%02d What format the minute label should be in (sprintf)
minute_value_format \%20d What format the minute value should be in (sprintf)
second_format \%02d What format the second label should be in (sprintf)
second_value_format \%20d What format the second value should be in (sprintf)
field_array n/a Outputs values to array of this name
all_extra null Adds extra attributes to select/input tags if given
hour_extra null Adds extra attributes to select/input tags if given
minute_extra null Adds extra attributes to select/input tags if given
second_extra null Adds extra attributes to select/input tags if given
meridian_extra null Adds extra attributes to select/input tags if given
field_separator \n String printed between different fields
option_separator \n String printed between different options of a field
all_id null Adds id-attribute to all select/input tags if given
hour_id null Adds id-attribute to select/input tags if given
minute_id null Adds id-attribute to select/input tags if given
second_id null Adds id-attribute to select/input tags if given
meridian_id null Adds id-attribute to select/input tags if given
all_empty null If supplied then the first element of any select-box has this value as it's label and "" as it's value. This is useful to make the select-boxes read "Please select" for example.
hour_empty null If supplied then the first element of the hour's select-box has this value as it's label and "" as it's value. This is useful to make the select-box read "Please select an hour" for example.
minute_empty null If supplied then the first element of the minute's select-box has this value as it's label and "" as it's value. This is useful to make the select-box read "Please select an minute" for example.
second_empty null If supplied then the first element of the second's select-box has this value as it's label and "" as it's value. This is useful to make the select-box read "Please select an second" for example.
meridian_empty null If supplied then the first element of the meridian's select-box has this value as it's label and "" as it's value. This is useful to make the select-box read "Please select an meridian" for example.

Examples

{html_select_time use_24_hours=true}

At 9:20 and 23 seconds in the morning the template above would output:

<select name="Time_Hour">
    <option value="00">00</option>
    <option value="01">01</option>
    ... snipped ....
    <option value="08">08</option>
    <option value="09" selected>09</option>
    <option value="10">10</option>
    ... snipped ....
    <option value="22">22</option>
    <option value="23">23</option>
</select>
<select name="Time_Minute">
    <option value="00">00</option>
    <option value="01">01</option>
    ... snipped ....
    <option value="19">19</option>
    <option value="20" selected>20</option>
    <option value="21">21</option>
    ... snipped ....
    <option value="58">58</option>
    <option value="59">59</option>
</select>
<select name="Time_Second">
    <option value="00">00</option>
    <option value="01">01</option>
    ... snipped ....
    <option value="22">22</option>
    <option value="23" selected>23</option>
    <option value="24">24</option>
    ... snipped ....
    <option value="58">58</option>
    <option value="59">59</option>
</select>
<select name="Time_Meridian">
    <option value="am" selected>AM</option>
    <option value="pm">PM</option>
</select>

See also $smarty.now, {html_select_date} and the date tips page.