6

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.

1
  • 1
    Hi Alex and welcome to Tridion Stack Exchange! Commented Jul 9, 2015 at 18:35

2 Answers 2

9

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 );
5

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!

Your Answer

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

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