<p>You're close! If there's one thing I've learned about Twig, it's easy to overthink it... </p>

<p>Create an array with the first date, then <a href="http://twig.sensiolabs.org/doc/filters/merge.html" rel="nofollow">merge</a> the rest of dates into the same array with a for loop. Just increment the day in the range:</p>

<pre><code> {% set rangeOfDates = [ now|date("l dS F Y") ] %}

 {% for i in range (1,13) %}

     {% set rangeOfDates = rangeOfDates|merge( [ now|date_modify("+" ~ i ~ " day")|date("l dS F Y") ]) %}

{%endfor%}
</code></pre>

<p>Then in your forms macro:</p>

<pre><code>{{ forms.select({
    options: rangeOfDates
}) }}
</code></pre>

CC BY-SA 3.0
2015-06-24T21:21:28.923Z
So simple, twig rocks. One problem with the above code is that the variable `dates` in the for loop doesn't exist, it needs to be rangeOfDates. If you update you answer with `{% set rangeOfDates = rangeOfDates|merge( [ now|date_modify("+" ~ i ~ " day")|date("l dS F Y") ]) %}` I will mark it as correct.
since1976
CC BY-SA 3.0
2015-06-25T20:16:29.250Z
Oops thank you, fixed! In the spirit of clarify I had changed the variable name at the last minute but of course forgot to change it in that critical spot!
RitterKnight
CC BY-SA 3.0
2015-06-24T05:08:01.717Z
2015-06-25T20:15:10.853Z
2015-06-25T20:15:10.853Z
RitterKnight
<p>I'm looking to create a select (dropdown) form field that includes the days and dates for the next 14 days, starting from today, as options. </p>

<p>My initial thoughts on how to construct this would be to set today <code>{% set today = now|date("l dS F Y") %}</code> and then set a date 13 days from now <code>{% set finalDate = now|date_modify("+13 day")|date("l dS F Y") %}</code> and then somehow put that into a range loop. It is the last part I'm having trouble getting working, if it is at all possible.</p>

<p>Once I have that range I would ultimately like to pass it as option values to the <a href="https://craftcms.stackexchange.com/questions/10307/how-can-i-add-an-option-group-to-the-select-macro-from-craftcms-forms-macros">select macro mentioned in another question</a> like so:</p>

<pre><code>{{ forms.select({
    options: ['Today', 'Tomorrow', ...]
}) }}
</code></pre>

<p>Thanks</p>

<datetime><macro><range>
How would I create a select element with the 14 days from today as options
# How would I create a select element with the 14 days from today as options

(Asked by: username_0 on 2015-06-24)

I'm looking to create a select (dropdown) form field that includes the days and dates for the next 14 days, starting from today, as options. 
My initial thoughts on how to construct this would be to set today {% set today = now|date("l dS F Y") %} and then set a date 13 days from now {% set finalDate = now|date_modify("+13 day")|date("l dS F Y") %} and then somehow put that into a range loop. It is the last part I'm having trouble getting working, if it is at all possible.
Once I have that range I would ultimately like to pass it as option values to the select macro mentioned in another question like so:
{{ forms.select({
    options: ['Today', 'Tomorrow', ...]
}) }}

Thanks

**Tags:** datetime, macro, range

---

## 1 answers

### Answer by username_1 on 2015-06-24. Score: 5 | Accepted answer

You're close! If there's one thing I've learned about Twig, it's easy to overthink it... 
Create an array with the first date, then merge the rest of dates into the same array with a for loop. Just increment the day in the range:
 {% set rangeOfDates = [ now|date("l dS F Y") ] %}

 {% for i in range (1,13) %}

     {% set rangeOfDates = rangeOfDates|merge( [ now|date_modify("+" ~ i ~ " day")|date("l dS F Y") ]) %}

{%endfor%}

Then in your forms macro:
{{ forms.select({
    options: rangeOfDates
}) }}

> **Comments:**
> **username_0**: So simple, twig rocks. One problem with the above code is that the variable `dates` in the for loop doesn't exist, it needs to be rangeOfDates. If you update you answer with `{% set rangeOfDates = rangeOfDates|merge( [ now|date_modify("+" ~ i ~ " day")|date("l dS F Y") ]) %}` I will mark it as correct.  
> **username_1**: Oops thank you, fixed! In the spirit of clarify I had changed the variable name at the last minute but of course forgot to change it in that critical spot!  

---

