Answers.Body: <p>I think you may find that, although the search results show the relative dates converted to fixed dates, when you create a smart group from the results it will save the relative date range.  </p>
  
  <p>That is certainly what happens in my live v4.4.</p>
  
  <p>I have also checked this as best I can on a 4.7.10 site that has had no activity or changes on it since February this year. I have a smart group based on a search that used the relative date filter <strong>Previous month</strong>.  That group has no contacts now and if I go to <strong>Edit smart group search criteria...</strong> (via the Contacts link on the Manage Groups page) I see:</p>
  
  <blockquote>
    <p>No matches found for:
     ...AND Activity Date - greater than or equal to "01 July 2016 12:00
    AM" AND less than or equal to "31 July 2016 11:59 PM" ...AND.</p>
  </blockquote>
  
  <p>but when I click on <strong>Edit smart group search criteria...</strong> for the second time it shows me the actual search parameters which include: </p>
  
  <blockquote>
    <p>Activity date :<strong>Previous Calendar month</strong></p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-19T06:38:26.980Z
Answers.Text: It does not update for me in v4.7.9, so I am trying to test that in Sandbox, but apparently the Smart groups are reset daily. **How can I test that?** Also, what does Smart Group show in v4.4? For instance, can you see there relative ranges like Today, Yesterday, Last month or does it show fixed dates that are automatically updated daily?
Answers.UserDisplayName: Aivars
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-19T13:00:08.647Z
Answers.Text: It shows fixed dates that are automatically updated daily/monthly , but the actual search criteria is saved with a relative date,  I have updated my answer to explain this in more detail.
Answers.UserDisplayName: JoAnne
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-20T08:30:48.823Z
Answers.Text: Thank you very much for the detailed answer. I can clearly see that it works for you as it is expected. 
  
  However, CiviCRM behaves very differently on my site. See **STEP 4. EDIT SMART GROUP** in my comment below. I just tested it on **CiviCRM Drupal Sandbox** and it behaves exactly the same. Namely, when you click Edit, you don't see the relative date there. I could not test it in CiviCRM Wordpress Sandbox - the system won't give me permission to see the contacts that I create. Is not that strange that relative dates would not work in 4.7.9 and 4.7.11, but do in 4.7.10? What do I do now?
Answers.UserDisplayName: Aivars
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-20T08:46:34.483Z
Answers.Text: I am starting to think that relative date filters work in smart groups created prior to an upgrade to 4.7 ( or perhpas even 4.6), but smart groups created in 4.7 don't work with relative date filters.  I am testing further.
Answers.UserDisplayName: JoAnne
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-21T23:50:40.867Z
Answers.Text: @Aivars I have confirmed this as a bug for new groups in 4.7.10 and will create an issue for it.
Answers.UserDisplayName: JoAnne
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-19T01:41:55.483Z
Answers.LastActivityDate: 2016-08-19T13:17:25.217Z
Answers.LastEditDate: 2016-08-19T13:17:25.217Z
Answers.UserDisplayName: JoAnne
Answers.Body: <p>Let me clarify the sequence and point to some strange behavior.</p>
  
  <h2>STEP 1. ADVANCED SEARCH</h2>
  
  <p>Open <em>Advanced search</em> and go straight to <em>Activities</em> (without changing anything else). </p>
  
  <p>Choose Activity Type (=Phone Call), relative Activity Date (=<strong>Today</strong>), Activity Status (=<strong>Unreachable</strong>). Click <em>Search</em>.</p>
  
  <p><a href="https://i.sstatic.net/uXRN1.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/uXRN1.png" alt="Advanced search"></a></p>
  
  <h2>STEP 2. CREATE SMART GROUP</h2>
  
  <p>I see Activity Date has been replaced from relative <strong>Yesterday</strong> to fixed August 18th.</p>
  
  <p>I create a Smart group by Selecting all records and choosing the Action <strong>Group - create smart group</strong>.</p>
  
  <p><a href="https://i.sstatic.net/itGlX.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/itGlX.png" alt="Create Smart group"></a></p>
  
  <h2>STEP 3. SMART GROUP PARAMETERS</h2>
  
  <p>Not much here, but note that Activity Date here is also listed as fixed - August 18th (not <strong>Yesterday</strong>).</p>
  
  <p>I click the <em>Save Smart Group</em> button.</p>
  
  <p><a href="https://i.sstatic.net/ubB8W.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ubB8W.png" alt="Smart group"></a></p>
  
  <h2>STEP 4. EDIT SMART GROUP.</h2>
  
  <p>That is where all the fun begins. </p>
  
  <p><strong>First</strong>, if I do nothing, the Smart Group stays fixed to the particular date and never gets updated to new values.</p>
  
  <p><strong>Second</strong>, if I try to Edit the Smart Group, it shows entirely different search parameters. </p>
  
  <ul>
  <li>Relative Activity date field is empty.</li>
  <li>There is a fixed date value in Activity date field.</li>
  <li>Activity status <strong>Unreachable</strong> has been changed to <strong>Completed</strong> and <strong>Scheduled</strong>.</li>
  </ul>
  
  <p><a href="https://i.sstatic.net/nvrJu.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nvrJu.png" alt="Edit Smart group"></a></p>
  
  <h2>SUMMARY.</h2>
  
  <ul>
  <li>The unexpected change of parameters in Edit mode has a very buggy feel.</li>
  <li>Relative date values are transformed to fixed which do not get updated.
  
  <ul>
  <li>Scheduled Job - Rebuild Smart Group Cache (no parameters) does not help.</li>
  </ul></li>
  <li>I can not test this on CiviCRM Sandbox, because database is being reset daily(?).</li>
  <li>@JoAnne reports the Relative dates work in Smart groups in v4.4</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-19T09:26:29.880Z
Answers.LastActivityDate: 2016-08-19T09:26:29.880Z
Answers.UserDisplayName: Aivars
Body: <p>According to CiviCRM user guide article's <em>Searching</em> section <a href="https://docs.civicrm.org/user/en/stable/the-user-interface/searching/#the-date-range-filter" rel="nofollow noreferrer"><strong>The Date Range Filter</strong></a>:</p>
  <blockquote>
  <p>Relative date ranges are especially useful for searches that you would
  like to then save as Smart Groups (automatically populated groups that are configured to include contacts that share a certain set of characteristics or activities).</p>
  </blockquote>
  <p>However, it seems that it is actually impossible to use them this way, because during search <em>relative dates</em> (e.g. Today) are transformed into <em>fixed dates</em> (e.g. August 18th).</p>
  <p><strong>See:</strong> <a href="https://civicrm.stackexchange.com/questions/14432/how-to-use-smart-groups-with-relative-dates">How to use Smart Groups with relative dates?</a> and
  <a href="https://civicrm.stackexchange.com/questions/12278/smart-group-change-log-creteria">smart group change log criteria</a></p>
  <p>Is it a recent bug or has it been like this forever? Will there be a fix for that?</p>
  
Tags: <search><smartgroups><dates>
Title: Is it a bug that Relative Dates are broken in Search and Smart Groups?
ThreadText: # Is it a bug that Relative Dates are broken in Search and Smart Groups?
  
  (Asked by: username_0 on 2016-08-18)
  
  According to CiviCRM user guide article's *Searching* section [**The Date Range Filter**](https://docs.civicrm.org/user/en/stable/the-user-interface/searching/#the-date-range-filter):
  
  > Relative date ranges are especially useful for searches that you would
  > like to then save as Smart Groups (automatically populated groups that are configured to include contacts that share a certain set of characteristics or activities).
  
  However, it seems that it is actually impossible to use them this way, because during search *relative dates* (e.g. Today) are transformed into *fixed dates* (e.g. August 18th).
  
  **See:** [How to use Smart Groups with relative dates?](https://civicrm.stackexchange.com/questions/14432/how-to-use-smart-groups-with-relative-dates) and
  [smart group change log criteria](https://civicrm.stackexchange.com/questions/12278/smart-group-change-log-creteria)
  
  Is it a recent bug or has it been like this forever? Will there be a fix for that?
  
  **Tags:** search, smartgroups, dates
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2016-08-19. Score: 2
  
  I think you may find that, although the search results show the relative dates converted to fixed dates, when you create a smart group from the results it will save the relative date range.
  
  That is certainly what happens in my live v4.4.
  
  I have also checked this as best I can on a 4.7.10 site that has had no activity or changes on it since February this year. I have a smart group based on a search that used the relative date filter **Previous month**. That group has no contacts now and if I go to **Edit smart group search criteria...** (via the Contacts link on the Manage Groups page) I see:
  
  > No matches found for:
  > ...AND Activity Date - greater than or equal to "01 July 2016 12:00
  > AM" AND less than or equal to "31 July 2016 11:59 PM" ...AND.
  
  but when I click on **Edit smart group search criteria...** for the second time it shows me the actual search parameters which include:
  
  > Activity date :**Previous Calendar month**
  
  > **Comments:**
  > **username_0**: It does not update for me in v4.7.9, so I am trying to test that in Sandbox, but apparently the Smart groups are reset daily. **How can I test that?** Also, what does Smart Group show in v4.4? For instance, can you see there relative ranges like Today, Yesterday, Last month or does it show fixed dates that are automatically updated daily?  
  > **username_1**: It shows fixed dates that are automatically updated daily/monthly , but the actual search criteria is saved with a relative date,  I have updated my answer to explain this in more detail.  
  > **username_0**: Thank you very much for the detailed answer. I can clearly see that it works for you as it is expected.   However, CiviCRM behaves very differently on my site. See **STEP 4. EDIT SMART GROUP** in my comment below. I just tested it on **CiviCRM Drupal Sandbox** and it behaves exactly the same. Namely, when you click Edit, you don't see the relative date there. I could not test it in CiviCRM Wordpress Sandbox - the system won't give me permission to see the contacts that I create. Is not that strange that relative dates would not work in 4.7.9 and 4.7.11, but do in 4.7.10? What do I do now?  
  > **username_1**: I am starting to think that relative date filters work in smart groups created prior to an upgrade to 4.7 ( or perhpas even 4.6), but smart groups created in 4.7 don't work with relative date filters.  I am testing further.  
  > **username_1**: @username_0 I have confirmed this as a bug for new groups in 4.7.10 and will create an issue for it.  
  
  ---
  
  ### Answer by username_0 on 2016-08-19. Score: 1
  
  Let me clarify the sequence and point to some strange behavior.
  
  ## STEP 1. ADVANCED SEARCH
  
  Open *Advanced search* and go straight to *Activities* (without changing anything else).
  
  Choose Activity Type (=Phone Call), relative Activity Date (=**Today**), Activity Status (=**Unreachable**). Click *Search*.
  
  [![Advanced search](https://i.sstatic.net/uXRN1.png)](https://i.sstatic.net/uXRN1.png)
  
  ## STEP 2. CREATE SMART GROUP
  
  I see Activity Date has been replaced from relative **Yesterday** to fixed August 18th.
  
  I create a Smart group by Selecting all records and choosing the Action **Group - create smart group**.
  
  [![Create Smart group](https://i.sstatic.net/itGlX.png)](https://i.sstatic.net/itGlX.png)
  
  ## STEP 3. SMART GROUP PARAMETERS
  
  Not much here, but note that Activity Date here is also listed as fixed - August 18th (not **Yesterday**).
  
  I click the *Save Smart Group* button.
  
  [![Smart group](https://i.sstatic.net/ubB8W.png)](https://i.sstatic.net/ubB8W.png)
  
  ## STEP 4. EDIT SMART GROUP.
  
  That is where all the fun begins.
  
  **First**, if I do nothing, the Smart Group stays fixed to the particular date and never gets updated to new values.
  
  **Second**, if I try to Edit the Smart Group, it shows entirely different search parameters.
  
  * Relative Activity date field is empty.
  * There is a fixed date value in Activity date field.
  * Activity status **Unreachable** has been changed to **Completed** and **Scheduled**.
  
  [![Edit Smart group](https://i.sstatic.net/nvrJu.png)](https://i.sstatic.net/nvrJu.png)
  
  ## SUMMARY.
  
  * The unexpected change of parameters in Edit mode has a very buggy feel.
  * Relative date values are transformed to fixed which do not get updated.
    + Scheduled Job - Rebuild Smart Group Cache (no parameters) does not help.
  * I can not test this on CiviCRM Sandbox, because database is being reset daily(?).
  * @username_1 reports the Relative dates work in Smart groups in v4.4
  
  
  ---
  
  