locked
Filter record based on 2 dates RRS feed

  • Question

  • On my entity, I have 2 fields : [startdate] and [enddate]. 
    In a view, I need to show all the records where today is between these [startdate] and [enddate]. 

    I tried to choose "On or Before", but the associatied date is fixed. Impossible to set the date as "today"
    What criteria should I choose in the filter screen?

    Thanks in advance
    Thursday, March 13, 2014 3:01 PM

Answers

  • Think of it a different way round - you want to view records where start date is in the past, and end date is in the future.

    There is no direct condition for "In the past" and "in the future" but you can fake it:

    Start Date is in the Last X Years where X = 99

    End Date is in the Next X Years where X = 99

    This should so the trick...

    Note that Last (or Next) X <time period> is "from this moment back (or forward) X amount of periods eg years, months to the same time of day on the past (future) date". If your start or end date is displayed as a date only and is today, then this means midnight this morning so it will be in the past. So you will see things that start today, but not ones that end today (because the end date is in the past by some number of hours). If that is a problem, you might need to use a second end date field that is maintained as "end date + 1 day" (by workflow or plugin). use this enddate+1 field for your filter, but don't make it visible to the user on the form or in the view.


    Hope this helps.
    Adam Vero, Microsoft Certified Trainer | Microsoft Community Contributor 2011
    UK CRM Guru Blog

    • Proposed as answer by Adam Vero Thursday, March 13, 2014 5:56 PM
    • Marked as answer by Osmont Emmanuel Thursday, March 20, 2014 1:25 PM
    Thursday, March 13, 2014 5:56 PM

All replies

  • Hi,
    it's not possible to build this query inside a view.


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Thursday, March 13, 2014 4:08 PM
  • Think of it a different way round - you want to view records where start date is in the past, and end date is in the future.

    There is no direct condition for "In the past" and "in the future" but you can fake it:

    Start Date is in the Last X Years where X = 99

    End Date is in the Next X Years where X = 99

    This should so the trick...

    Note that Last (or Next) X <time period> is "from this moment back (or forward) X amount of periods eg years, months to the same time of day on the past (future) date". If your start or end date is displayed as a date only and is today, then this means midnight this morning so it will be in the past. So you will see things that start today, but not ones that end today (because the end date is in the past by some number of hours). If that is a problem, you might need to use a second end date field that is maintained as "end date + 1 day" (by workflow or plugin). use this enddate+1 field for your filter, but don't make it visible to the user on the form or in the view.


    Hope this helps.
    Adam Vero, Microsoft Certified Trainer | Microsoft Community Contributor 2011
    UK CRM Guru Blog

    • Proposed as answer by Adam Vero Thursday, March 13, 2014 5:56 PM
    • Marked as answer by Osmont Emmanuel Thursday, March 20, 2014 1:25 PM
    Thursday, March 13, 2014 5:56 PM
  • Guido & Adam 

    Thanks for your help. Finally, I will use the Adam's solution.


    Thursday, March 20, 2014 1:25 PM