We have a requirement to list all the SharePoint calendar list item that "EventDate" date field is larger then 30 days before today and less than 60 days after today.
I've constructed the two dates already.
let pastDate = new Date(new Date().setDate(new Date().getDate() - 30));
let futureDate = new Date(new Date().setDate(new Date().getDate() + 60));
Can someone help to provide the filter below that for the query?
sp.web.lists.getByTitle("PubsMeeting").items.filter(??????).top(100).orderBy('EventDate').get()
It seems to be easy in REST calls as people used here.
http://neganov.blogspot.com/2013/06/filtering-items-by-date-range-using.html
However, it's seems to be difficult in the PnP js.
Your help is highly appreciated!!!
I've figured the solution.
let pastDate = new Date(new Date().setDate(new Date().getDate() - 30));
let futureDate = new Date(new Date().setDate(new Date().getDate() + 60));
let pastDateString = pastDate.toISOString();
let futureDateString = futureDate.toISOString();
sp.web.lists.getByTitle("PubsMeeting").items.filter('EventDate ge datetime' + "'" + pastDateString + "'" + ' and EventDate le datetime' + "'" + futureDateString + "'").top(100).orderBy('EventDate').get().then((response) => {
}
Thanks.
@harrychen1 can You please provide screen shot of Your code? Cannot get Your sample working..
update: argh, Ok, it works..
let timeNow = new Date().toISOString();
sp.web.lists.getByTitle(libTitle).items
.filter(`End_Time ge datetime'${timeNow}' and Start_Time le datetime'${timeNow}'`)
.select('Title', 'Start_Time', 'End_Time')
.orderBy('Start_Time', true).get()
.then(
(response: any[]) => {
const itemsCollection: ListItem[] = response.map(item => new ListItem(item));
this.setState({ items: itemsCollection }, () => {
console.log('State is set.');
});
});
Thank You for sharing.
@Gennady-G,
const d = new Date();
items.filter(`DateField ge datetime'${d.toISOString()}'`)
UPD: Missed your comment appeared while I was posting =)
Thank You @koltyakov !
Most helpful comment
@harrychen1 can You please provide screen shot of Your code? Cannot get Your sample working..
update: argh, Ok, it works..
Thank You for sharing.