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

  • Home
  • SEARCH
  • 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 8273107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:21:54+00:00 2026-06-08T07:21:54+00:00

In my very simple query to find Deposit objects for a date range: String

  • 0

In my very simple query to find Deposit objects for a date range:

    String sqlQuery ="select d from Deposit d where status in('PENDING', 'SKIPPED') and  d.depositDate <= '${endDateString}'"

    def allUnprocessedDeposits = Deposit.executeQuery(sqlQuery)

no rows whose depositDate is equal to endDateString are returned. (?!?) For example, if I update all d.depositDate rows to be the the same date, and provide that date as the endDateString, no rows are returned.

Using grails 2.0.3 and MySql 5.1…

Thanks to anyone with the answer. This seems so very simple, yet annoyingly fails.

  • 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-08T07:21:56+00:00Added an answer on June 8, 2026 at 7:21 am

    Given the information you’ve provided, the most likely explanation is that depositDate column is defined as DATETIME or TIMESTAMP. Note that these datatypes store the time value (in resolution down to a second) in addition to the date. e.g.

    '2012-07-20 11:35:46'
    

    A compare of a DATETIME value So a a DATE literal (without time component), e.g.

    '2012-07-20 11:35:46' <= '2012-07-20'
    

    is equivalent to a compare with a DATETIME literal with a time value of midnight:

    '2012-07-20 11:35:46' <= '2012-07-20 00:00:00'
    

    Which is obviously going to return FALSE. That’s the most likely explanation of why your query isn’t returning rows you expect it to.


    Suggested Fix:

    For predicates on DATETIME and TIMESTAMP columns, the normal pattern to get a “day” is to do a range scan from midnight of a given day up to midnight of the following day. What we want to check is whether the column is LESS THAN midnight of the following day:

    '2012-07-20 11:35:46' < DATE_ADD('2012-07-20', INTERVAL 1 DAY)
    

    That’s equivalent to comparing to midnight of the 21st.

    '2012-07-20 11:35:46' < '2012-07-21 00:00:00'
    

    In your case, since you already have an “end date” value, the easiest change for is to simply change the query text.

    Just add one day to the date value you pass in, and change the comparison operator from <= to <. (I’m assuming here that you are supplying only the date portion, and allowing the time portion to default to midnight.)

    ... d.depositDate < DATE_ADD('${endDateString}',INTERVAL 1 DAY)"
    

    We prefer this pattern because it works equally well on DATE, DATETIME and TIMESTAMP.

    (NOTE: Another reason we prefer this pattern is because it works with “point in time” values with even finer resolutions (e.g. Microsoft SQL Server DATETIME, which has a precision down to 3 ms, and doing a check of <= 23:59.59 winds up being insufficient.)

    Your code can ensure that the argument value is the date only, or is a date with a time component of midnight, but it’s easy to have the SQL query do this, by wrapping your argument in a a CAST( AS DATE)

    NOTE: you want to avoid wrapping the column reference d.depositDate inside any function, because that will disable MySQL’s ability to perform an index range scan operation (to satisfy the predicate).


    NOTE: all the usual warnings about SQL injection vulnerabilities apply here, if the argument value is supplied by the user, you want to either use bind parameters or escape the supplied …. values

    Consider what will happen when a malicious user supplies a value like:

    2012-07-20'; DELETE FROM Deposit ; SELECT '1
    

    Consider what statement(s) will get passed to the database. There are several approaches to dealing with this, to thwart such attacks.

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

Sidebar

Related Questions

I have very simple query like this: SELECT * FROM `all_conversations` WHERE `deleted_1` !=
I have a very simple query $this->db->select('id, title'); $this->db->order_by('id', 'DESC'); $query = $this->db->get('journal'); foreach($query->result()
I have a very simply query like this: SELECT users.id, COUNT(others.id) as c FROM
I use a very simple query with Like to find product by its name
I have a very simple query: The variable '_dc' is the Entity Framework Code
I have a very simple query that's giving me unexpected results. Hints on where
I created a simple .Net web service which runs a very simple query (which
Just wondering if someone could help me with a very simple SQL query. I
The following simple query takes a very long time (several minutes) to execute. I
I have a very simple linq to sql query in C#: int acctNum =

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.