Skip to main content
1-Visitor
January 12, 2016
Question

need Query Spec to get objects modified Today or on a particular date.

  • January 12, 2016
  • 1 reply
  • 1443 views

Hi,

i want to fetch modified object list for particular date or today.

i tried to use below Query, but it wont give me results.

please point out my mistake in below query.

any help will be grate.

=================

DateFormat dateFormat1 = new SimpleDateFormat("dd/MM/yyyy");

  java.util.Date date1 = dateFormat1.parse("12/01/2015");

  long time1 = date1.getTime();

  Timestamp ts1= new Timestamp(time1);

  criteria.appendWhere(new SearchCondition(WTPart.class,"thePersistInfo.modifyStamp", SearchCondition.EQUAL, ts1), new int[] {0});

  criteria.appendAnd();

  criteria.appendWhere(new SearchCondition(WTPart.class, "iterationInfo.latest", "TRUE"));

  QueryResult qr= PersistenceHelper.manager.find(criteria);

  System.out.println("Query Size = "+qr.size());

=======================

Regards,

Vivek

1 reply

16-Pearl
January 12, 2016

Hi Vivek,

Try passing a date range instead of a particular timestamp. You can print the criteria object to see how the query is built.

long time2 = date2.getTime();

  Timestamp ts2= new Timestamp(time2);

  criteria.appendWhere(new SearchCondition(WTPart.class,"thePersistInfo.modifyStamp", SearchCondition.GREATER_THAN_OR_EQUAL, ts1), new int[] {0});

  criteria.appendAnd();

  criteria.appendWhere(new SearchCondition(WTPart.class,"thePersistInfo.modifyStamp", SearchCondition.LESS_THAN_OR_EQUAL, ts2), new int[] {0});

Regards,

Bhushan