I am populating a simple HTML select
list in a Smarty template with month names. A timestamp object is passed to the template. I would like the passed in timestamp month to be the default value of the select
. The passed value could be passed in as an int
(1,2,3,etc...) or a string
(jan,feb,mar,etc...).
To set a default, selected value I need to compare the passed in timestamp month to a timestamp I created in the template. For example, to compare to just the current month I would do something like this:
<option {if $smarty.now|date_format:"%b" = $passedInTimestamp['month']}selected{/if}>
text
</option>
$smarty.now
will only work for the current month obviously. My <option>
tag is inside a for loop, looping from 1 to 12. How can I create a timestamp with a specific month to compare to the passed in month?