ExcelScript.FilterDatetime interface

Represents how to filter a date when filtering on values.

Remarks

Examples

/**
 * This script applies a filter to a PivotTable that filters it
 * to only show rows from between June 20th, 2022 and July 10th, 2022.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the "Date Recorded" field to filter. 
  // The data in this field must be dates in order for the filter to work.
  const pivot = workbook.getPivotTables()[0];
  const rowHierarchy = pivot.getRowHierarchy("Date Recorded");
  const rowField = rowHierarchy.getFields()[0];

  // Create the filter's date boundaries.
  let earliestDate: ExcelScript.FilterDatetime = {
    date: "2022-06-20",
    specificity: ExcelScript.FilterDatetimeSpecificity.day
  };
  let latestDate: ExcelScript.FilterDatetime = {
    date: "2022-07-10",
    specificity: ExcelScript.FilterDatetimeSpecificity.day
  };

  // Apply the date filter.
  rowField.applyFilter({
    dateFilter: {
      condition: ExcelScript.DateFilterCondition.between,
      lowerBound: earliestDate,
      upperBound: latestDate
    }
  });
}

Properties

date

The date in ISO8601 format used to filter data.

specificity

How specific the date should be used to keep data. For example, if the date is 2005-04-02 and the specificity is set to "month", the filter operation will keep all rows with a date in the month of April 2005.

Property Details

date

The date in ISO8601 format used to filter data.

date: string;

Property Value

string

specificity

How specific the date should be used to keep data. For example, if the date is 2005-04-02 and the specificity is set to "month", the filter operation will keep all rows with a date in the month of April 2005.

specificity: FilterDatetimeSpecificity;

Property Value