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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:28:15+00:00 2026-06-17T15:28:15+00:00

Using DB2 SQL I would like to query for records since 2:00 yesterday. I

  • 0

Using DB2 SQL

I would like to query for records since 2:00 yesterday. I want a dynamic expression that frees me from having to manually enter the current date prior to running the query. The created_datetime attribute is of timestamp dataype.

For example:

select record_key, other_stuff
from table
where created_datetime > "2 o'clock PM yesterday"

Is this kind of dynamic timestamp comparison even possible? Eventually, I’d like to be able to do a window of time, which gets complicated!

select count(1)
from table
where created_datetime between "2 o'clock PM yesterday" and "2 o'clock PM today"

I am familiar with current date, but I am trying to conceptualize how I would leverage that. The following gets me close, but it includes everything 24 hours prior to whenever the query is run.

select count(1)
from table
where created_datetime between (currentdate - 1 day) and (currentdate @ 2 o'clock PM)

I know this is some pretty basic territory, and I feel guilty posting this question, but my research has not turned up anything for me so far. I appreciate every ounce of time spent on my behalf.

  • 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-17T15:28:16+00:00Added an answer on June 17, 2026 at 3:28 pm

    Try these

    select record_key, other_stuff
    from table
    where created_datetime > CURRENT DATE - 10 HOURS
    
    select count(1)
    from table
    where created_datetime between (CURRENT DATE - 10 HOURS) and (CURRENT DATE + 14 HOURS)
    
    select count(1)
    from table
    where created_datetime between (CURRENT DATE - 1 DAYS) and (CURRENT DATE + 14 HOURS)
    

    From the IBM Dev Works Library : DB2 Basics: Fun with Dates and Times

    There are heaps of samples there.

    E.g.

    You can also perform date and time calculations using, for lack of a
    better term, English:

    current date + 1 YEAR 
    current date + 3 YEARS + 2 MONTHS + 15 DAYS 
    current time + 5 HOURS - 3 MINUTES + 10 SECONDS 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using a DB2 Database. What would be a suitable SQL query to find
I am using IBM DB2. I want to introduce jamon to track sql performance.
i have problem using LIKE structure in DB2 : for example: select * from
Can SQL Server or db2 do entire database exports like oracle (using exp command)?
I would like to connect to a DB2 database, specifically an iSeries version, using
Hi im using sqlalchemy on a db2 table with 500k rows. using plain sql
I'm using Db2 on AS/400, and I am trying to execute a JPQL query
I am using db2 and I want to find tables, having a column named
Hibernate criteria, using DB2 dialect, generates the following SQL with composite keys in the
I have 10+ SQL Server databases, from where I would use one table from

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.