Answers.Body: <p>Yes, a date field is a good idea. For the following example I'm using a date field "startDate" in a global set "classes". And for the classes entries I set up a dropdown field "weekday" with values "monday, thuesday, ..." and localized labels "Montag, Dienstag, ...".</p>
  
  <p>Twig's <a href="http://twig.sensiolabs.org/doc/filters/date_modify.html" rel="nofollow"><code>date_modify</code></a> filter does all the calculation for this:</p>
  
  <pre><code>{% set weekday = entry.weekday %}
  {% set classDate = classes.startDate|date_modify(weekday) %}
  
  {{ classDate|date('l, F j, Y') }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-25T07:45:01.153Z
Answers.Text: Heres a question which shows a bunch of examples of what you can do with the `date_modify` filter :) http://craftcms.stackexchange.com/questions/170/how-to-show-events-for-this-weekend-next-week/171#171
Answers.UserDisplayName: Alec Ritson
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-25T07:51:03.907Z
Answers.Text: You can basically pass any relative date or time format PHP understands: http://php.net/manual/en/datetime.formats.relative.php.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-31T04:10:49.023Z
Answers.Text: Thanks this is exactly what I need.
  Is there somewhere can I find a life of all of the outputs for the different letters in `|date('l, F j, Y')`?
Answers.UserDisplayName: JeffTalbot
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-31T08:10:32.447Z
Answers.Text: Yes @falour, have a look at the list of letters PHP's date function understands: http://php.net/manual/en/function.date.php
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-25T07:03:44.123Z
Answers.LastActivityDate: 2015-08-25T07:03:44.123Z
Answers.UserDisplayName: carlcs
Body: <p>Im working on a school website where the client would like a global date that is the start and finish of all the classes. This part is easy as I have made a Global where you enter the Start and End dates for the semester. At the moment this is just a text field.</p>
  
  <p>The next challenge is to make it add days onto the start and end date depending on what day a class starts on.
  So for example:
  If I say the week starts on a Monday and set the starting date to the 20/10/2015. If the class is also on a Monday it will not change the date. But if the class is a Tuesday it will add +1 to the date making the starting date the 21st. (Wednesday +2, Thursday +3, Friday +4, Saturday, +5, Sunday +6) This would be easy except that if the day goes above how many days there are in a month. for example if the starting date is 28/10/2015 on Friday it would list as 32/10/2015 but would need to be changed to the 01/11/2015.</p>
  
  <p>Does anyone know of a way that I can write this? Would using the date field make this easier?</p>
  
Tags: <datetime><math>
Title: Date changing algorithm
ThreadText: # Date changing algorithm
  
  (Asked by: username_0 on 2015-08-25)
  
  Im working on a school website where the client would like a global date that is the start and finish of all the classes. This part is easy as I have made a Global where you enter the Start and End dates for the semester. At the moment this is just a text field.
  
  The next challenge is to make it add days onto the start and end date depending on what day a class starts on.
  So for example:
  If I say the week starts on a Monday and set the starting date to the 20/10/2015. If the class is also on a Monday it will not change the date. But if the class is a Tuesday it will add +1 to the date making the starting date the 21st. (Wednesday +2, Thursday +3, Friday +4, Saturday, +5, Sunday +6) This would be easy except that if the day goes above how many days there are in a month. for example if the starting date is 28/10/2015 on Friday it would list as 32/10/2015 but would need to be changed to the 01/11/2015.
  
  Does anyone know of a way that I can write this? Would using the date field make this easier?
  
  **Tags:** datetime, math
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-08-25. Score: 1 | Accepted answer
  
  Yes, a date field is a good idea. For the following example I'm using a date field "startDate" in a global set "classes". And for the classes entries I set up a dropdown field "weekday" with values "monday, thuesday, ..." and localized labels "Montag, Dienstag, ...".
  
  Twig's [`date_modify`](http://twig.sensiolabs.org/doc/filters/date_modify.html) filter does all the calculation for this:
  
  ```
  {% set weekday = entry.weekday %}
  {% set classDate = classes.startDate|date_modify(weekday) %}
  
  {{ classDate|date('l, F j, Y') }}
  
  ```
  
  > **Comments:**
  > **username_2**: Heres a question which shows a bunch of examples of what you can do with the `date_modify` filter :) http://craftcms.stackexchange.com/questions/170/how-to-show-events-for-this-weekend-next-week/171#171  
  > **username_1**: You can basically pass any relative date or time format PHP understands: http://php.net/manual/en/datetime.formats.relative.php.  
  > **username_0**: Thanks this is exactly what I need. Is there somewhere can I find a life of all of the outputs for the different letters in `|date('l, F j, Y')`?  
  > **username_1**: Yes @falour, have a look at the list of letters PHP's date function understands: http://php.net/manual/en/function.date.php  
  
  ---
  
  