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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:18:14+00:00 2026-05-25T06:18:14+00:00

I am trying to construct the SQL query, that should be executed as is

  • 0

I am trying to construct the SQL query, that should be executed as is
both on HSQL (v2.2.4) and MySQL (v5.1.36) server (if it can run also on DB2 v9, that would be wonderful bonus!)

The query is:

select count(*) from document where current_date - cast(indexing_date as date) <= ?

(here current_date is a standard HSQL/MySQL function and indexing_date is a column with type datetime, parameter ? is substituted by integer 20 which is the number of days).

The problem is that MySQL returns the difference between dates as between numbers while HSQL returns the difference in days (which is logical when you subtract date from date).

Also HSQL supports this syntax (but MySQL does not):

select count(*) from document where cast(indexing_date as date) between current_date - 20 day and current_date

while MySQL does not. I am aware about DATEDIFF() in MySQL, but as I said the solution should be inter-operable.

  • 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-05-25T06:18:15+00:00Added an answer on May 25, 2026 at 6:18 am

    HSQLDB also supports this:

    select count(*) from document where current_date - cast(indexing_date as date) <= cast(? as interval day)
    

    and

    select count(*) from document where cast(indexing_date as date) between current_date - '20' day and current_date
    

    or

    select count(*) from document where indexing_date >= current_date - interval '20' day
    

    Also, from version 2.2.6, HSQLDB supports DATEDIFF(datevaluea, datevalueb), which returns the number of days between the two dates, as well as DAYS(datevalue), which returns the day number since the epoch.

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

Sidebar

Related Questions

I'm trying to construct a SQL query that I think requires multiple JOIN's, but
I am trying to construct an sql query using a while loop that increments
I'm trying to construct a query that will include a column indicating whether or
I've been trying to construct a sql query with ZendFW, but I cant seem
I'm trying to construct my linq-to-sql expression so that it only generates a single
Trying to construct a query such that I have multiple statement specifying joins, each
I have a query in SQL that I'm trying to translate into Pig Latin
MSSQL 2008. I am trying to construct a SQL statement which returns the total
Am trying to construct a simple update query in my model class Model_DbTable_Account extends
I am trying to construct a Groovy statement to find values that don't exist

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.