I have query like this:
Criteria criteria = new ItemTypeCriteria(64);
var pages = new Query(criteria );
I also need to add criteria to get pages which were published after specific date.
I have query like this:
Criteria criteria = new ItemTypeCriteria(64);
var pages = new Query(criteria );
I also need to add criteria to get pages which were published after specific date.
You can use ItemLastPublishedDateCriteria
criteria to specify the last published date filter that you are looking for, for retrieving the pages that were published after specific date.
Given below is the sample code to achieve the same.
var itemTypeCriteria = new ItemTypeCriteria(64);
var lastPublishedCriteria = new ItemLastPublishedDateCriteria(<specify date>)
Criteria criteria = CriteriaFactory.And(itemTypeCriteria, lastPublishedCriteria);
var pages = new Query(criteria );
Just a little enhancement to the accepted answer given by Hiren above....
Presumably, you're not looking for the exact date and time (including the exact second!) that an item was published, so you're going to want to use second FieldOperator
parameter (e.g. Criteria.GreaterThanOrEqual
) when creating the ItemLastPublishedDateCriteria
objects, so you can effective specify 'before' or 'after' a specific time.
For example, here's an excerpt of some code I used recently:
DateTime startDate = new DateTime(2020, 02, 24, 11, 08, 00);
DateTime endDate = new DateTime(2020, 02, 24, 14, 39, 00);
ItemTypeCriteria itemTypeCriteria = new ItemTypeCriteria(64);
ItemLastPublishedDateCriteria lastPublishedCriteriaStart = new ItemLastPublishedDateCriteria(startDate, Criteria.GreaterThanOrEqual);
ItemLastPublishedDateCriteria lastPublishedCriteriaEnd = new ItemLastPublishedDateCriteria(endDate, Criteria.LessThanOrEqual);
Query query = new Query(CriteriaFactory.And(new Criteria[] { itemTypeCriteria, lastPublishedCriteriaStart, lastPublishedCriteriaEnd }));
List<string> pageTcmIds = query.ExecuteQuery().ToList();
Hope this helps!