2 Replies Latest reply on Feb 17, 2004 4:19 AM by vvijith

    Compare Dates in Finder Method

    neelsaeed Newbie

      Hello everybody,

      I was wondering if u could help me out.. I have the following finder method:

      @ejb.finder signature = "java.util.Collection findMemberSchedule(java.lang.String memberId, java.util.Date date)"
      query = "select object (sch) from Schedule sch, Member mem WHERE sch MEMBER OF mem.schedules AND mem.id=?1 AND sch.departureTime =?2"

      when I use this method, it returns an empty collection.
      The reason: When I send a date to be compared with the date in the DB, it tries to match the year, month, day, hour, minute, and second... I would only like to get the record matching today's date.. so, is there any way I could do that?
      The date in stored in a mySQL DB and is a dateTime.
      Thanks in advance..

        • 1. Re: Compare Dates in Finder Method
          Julien Dubois Newbie

          Create 2 dates :
          Date today;
          Date tomorrow;
          And initialize "today" with today's date at midnight, and "tomorrow" with tomorrow's date at midnight.
          Then you can do :
          (...) AND sch.departureTime >?2 AND AND sch.departureTime <?3

          That way you will get all of today's schedules.


          • 2. Re: Compare Dates in Finder Method
            vvijith Newbie

            Probably this may work out for you... with some amout of extra coding.

            The EJB QL for the finder would be

            SELECT OBJECT(o) from myBean as o where SUBSTRING(o.startdate,0,9) = ?1

            startdate is a date field in the database and the finder method will take string as the parameter.

            This string parameter should be the date that you want to check from the database. The default format for the date field from the database also matters in this approach.

            So the finder definition would be
            Collection findCustomersOnDate(java.lang.String date)
            //date ="16-FEB-04"

            The finder will return a collection and when you print the date field, you can always get the full date(ie untruncated)