Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8107979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:57:00+00:00 2026-06-06T00:57:00+00:00

I want to get a list of objects from the database between a given

  • 0

I want to get a list of objects from the database between a given date time range. How do I achieve that ? This is the solution I am currently using, but it doesn’t return anything… and the given values are correct.

public List getRegistrationsForUserOnDate(Date startdate, Date enddate){
        Set<Date> dateSet = new HashSet<Date>();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(enddate);

        while (calendar.getTime().before(startdate))
        {
            Date resultado = calendar.getTime();
            dateSet.add(resultado);
            calendar.add(Calendar.DATE, 1);
        }

        String query = "from Registration where date = '" + Validation.convertToValidDateTime(startdate, true) + "'";
        for(Date date : dateSet){
            query += " AND date = '" + Validation.convertToValidDateTime(date, true)+"'";
        }             
        return em.createQuery(query).getResultList();           
    }

for example:

startdate  = Fri Jun 15 12:07:31 CEST 2012

enddate = Wed Jun 13 12:07:31 CEST 2012 

Then this methods query looks like this (data copied from debug mode):

from TimeRegistration where date = '2012-06-15 00:00:00' AND date = '2012-06-14 00:00:00' AND date = '2012-06-13 00:00:00'

These are some sample fields that are present in the database:

id |       date          |comment|FK|FK|FK
132|"2012-06-08 00:00:00"|    "" | 6| 2| 1
133|"2012-06-15 00:00:00"|    "" | 8| 1| 1
134|"2012-06-14 00:00:00"|    "" | 3| 2| 1
135|"2012-06-13 00:00:00"|    "" | 1| 3| 1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:57:01+00:00Added an answer on June 6, 2026 at 12:57 am

    How can date equal two different dates? Not surprised you don’t get anything.

    date = ‘2012-06-15 00:00:00’ AND date = ‘2012-06-14 00:00:00’ – so if todays date is thursday and friday return it?

    Should you be using OR rather than AND, or better still, greater and less than or between?

    from TimeRegistration where date between '2012-06-13 00:00:00' and '2012-06-15 00:00:00'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a list of objects that I want to delete from the database.
I get from my database a list of objects with attributes. So I want
I want to get a list of all available datasets (that I'd creat in
I want to get a list of all sub-directories within a directory. If that
I want to get data from the database (MySQL) by JPA, I want it
I want to get a list of result sets and columns that i can
I want to achieve something relatively simple: I want to retrieve all objects from
I want to get list of Domino Servers on the network, and accordingly login
i want to get list of all application or Threads attached with a process.For
I want to get list of methods in current file, when my tool is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.