1

In my page, I have two date filters..

  1. Start Date
  2. End Date

I have done some settings that the filters are able to filter the list based on the start date and end date.

Now my requirement is that the date filters should automatically take the current week date such that start date should be the date of Monday and the end date should be the date of coming Sunday of the current week. Only current week items of the list should appear.

2 Answers 2

1

You can use below JavaScript code to get the start date and end date of current week.

Date.prototype.getWeek = function(start)
{
        //Calcing the starting point
    start = start || 0;
    var today = new Date(this.setHours(0, 0, 0, 0));
    var day = today.getDay() - start;
    var date = today.getDate() - day;

        // Grabbing Start/End Dates
    var StartDate = new Date(today.setDate(date));
    var EndDate = new Date(today.setDate(date + 6));
    return [StartDate, EndDate];
}

Use below in your custom date refinement template to get the start and end date of the week and update the search results:

    var Dates = new Date().getWeek();
    var fromValue =Dates[0].toISOString();
    var toValue =Dates[1].toISOString();
     // Create the refinement JSON value string
     var refinement = '{"'+ ctx.RefinementControl.propertyName +'":["range('+fromValue +','+toValue +')"]}';
    $getClientControl(this).updateRefinersJSON(refinement);
1

To filter a list to show the current week’s items or events, create two calculated columns with a data type of Date and Time (Date Only), and a view with filters based on the new columns.

I’ve included the formulas and view filters below. Visit my blog post on this topic for a more in-depth explanation and to view screenshots.

Column 1 Name:  Calc_WeekViewEnd
Column 1 Formula:  =[End Time]-WEEKDAY([End Time],2)+7

Column 2 Name:  Calc_WeekViewStart
Column 2 Formula:  =[Calc_WeekViewEnd]-7

View Name:  This Week
View Filters:  Calc_WeekViewStart is less than or equal to [Today], AND, Calc_WeekViewEnd is greater than or equal to [Today]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.