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 8887137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:43:57+00:00 2026-06-14T21:43:57+00:00

We are using Java and querying MongoDB. Want to get the records from a

  • 0

We are using Java and querying MongoDB.
Want to get the records from a previous day. For example, we want to get all the students that enrolled yesterday. Here is the query that we use,

Date toDay = new Date();            
Date twoDaysBack  = Util.twoDaysBack(toDay);
query.put("enroldate", new BasicDBObject("$gt", twoDaysBack).append("$lt", toDay));

Say, if today is 22nd Nov, 2012. This query shows the list of students enrolled on 21st as well as 22nd even though we have specified $lt for today.

What is the issue here?

  • 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-14T21:43:59+00:00Added an answer on June 14, 2026 at 9:43 pm

    Tha Java Date object doesn’t just include the day, but also the time, accurate to the second. So when you create a new Date(), you get the current date with the current time. Any earlier date today is less than it. When your database includes the date without a time, it is treated as November 22nd 2012 00:00:00. This is less than November 22nd 2012 11:05:22

    Solution: Set the hours, minutes and seconds of toDay to 0 to exclude any dates which were today.

    By the way: Many Java programmers consider the library jodatime far superior to Java’s native date and time handling classes. This begins with its equivalent to java.util.Date having the less misleading name DateTime.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Java (1.6) I want to split an input string that has components of
Using Java, how can I extract all the links from a given web page?
I am using java java.sql.* for querying from SQLite DB. I found a starnge
I'm querying MSSQL 2008 server thourgh JAVA, using the JDBC driver. I do something
I want to create a simple application using Jena and SPARQL, that inserts, deletes,
When using JDBC in Java, the generally accepted method of querying a database is
Using Java,I have to fetch multiple sets of values from an XML file to
I'm using Sqlite with Java using SQLiteJDBC . When querying sqlite, I've found out
I convert the DB from Oracle to MySQL. I'm using both Java & Hibernate.
I want to retrieve a user's busy times using the new querying busy times

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.