Question

I am using PnPjs to query a SharePoint list. I am using this code:

let today: string = (new Date()).toISOString(); 
today = `${today.substring(0, today.indexOf('T'))}T00:00:00Z`
let results = await sp.web.lists.getByTitle('my list').items
.filter(`datetime'${today}' ge myStartDate and datetime'${today}' le myEndDate`).get()

However, this is not filtering the right data as for example, today's date has the T00:00:00Z and it excludes the start date when in the same day as it has a value more than T:00:00:Z.. how do we compare date/no time?

Was it helpful?

Solution

In SharePoint, date field uses ISO8601 DateTime format. We cannot just filter the date only.

As a workaround, you could use T23:59:59Z in today's date for start date and T00:00:00Z for end date

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top