0 Replies Latest reply on Dec 12, 2009 10:31 PM by Sven Kilchenmann

    CreatQuery with date

    Sven Kilchenmann Newbie

      I have an event class

           private Date startDate = new Date();..

      now i create a query which will select all events within a date range.

      startCal = new GregorianCalendar();
               startCal.setTime(new Date());
                startCal.add(GregorianCalendar.DAY_OF_MONTH, 15);
                startCal.add(GregorianCalendar.AM_PM, GregorianCalendar.AM);
                endCal = new GregorianCalendar();
                endCal.setTime(new Date());
                endCal.add(GregorianCalendar.DAY_OF_MONTH, 15);
                endCal.add(GregorianCalendar.AM_PM, GregorianCalendar.PM);
               List<Event> events = (List<Event>) this.entityManager.createQuery("SELECT e FROM Event e WHERE e.startDate > :startDate AND e.startDate < :endDate")
               .setParameter("startDate", startCal.getTime())
               .setParameter("endDate", endCal.getTime())
               log.info("Found {0} events - {1} bis {2}",events.size(), startCal.getTime(), endCal.getTime());

      but if the date from database matches i don't have any entries within events.
      Anyone could help!
      Thanks a lot