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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:21:27+00:00 2026-05-12T15:21:27+00:00

I want to select records that have a created date between the first and

  • 0

I want to select records that have a created date between the first and the last day of a given month. I calculate the month with begin and enddate the following way:

The Date “month” is just a random date inside the timeframe

Calendar cal = Calendar.getInstance();
cal.setTime(month);
int endday = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
int actualmonth = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);

Date begin = format.parse("01." + actualmonth + "." + year);
Date end = format.parse(endday + "." + actualmonth + "." + year);

When I think about this, I’d actually have to set the daytime as well, to avoid records going missing on the last day of the month.

I feel this is kinda inelegant, anyone up for a better solution?

  • 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-12T15:21:27+00:00Added an answer on May 12, 2026 at 3:21 pm

    What I would do is create a Calendar and set the month and year to the month you want, the day to 1, hour, minute and millisecond to zero. Then take the date of that for your begin range. Then I’d add a month, and then subtract a millisecond. Take the date of that for your end range.

      Calendar dateCal = Calendar.getInstance();
      dateCal.set(Calendar.MONTH, month);
      dateCal.set(Calendar.YEAR, year);
      dateCal.set(Calendar.HOUR_OF_DAY, 0);
      dateCal.set(Calendar.MINUTE, 0);
      dateCal.set(Calendar.SECOND, 0);
      dateCal.set(Calendar.MILLISECOND, 0);
      Date startDate = dateCal.getTime();
    
      dateCal.add(Calendar.MONTH, 1)
      dateCal.add(Calendar.MILLISECOND, -1);
      Date endDate = dateCal.getTime();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to select records that are 1 month old or newer. The query
I want to select the topmost element in a document that has a given
I have a data set that i am attempting to select the first record
If the primary keys of the records are 1,3,4,5,6,8 I want to select the
I have a select statement, retrieve about 1000 record I want to modify it
i have users table and i have posts table i want select from users
I want to SELECT a formatted date string from a datetime type in SQL
Say I want to get ten records with the MOST likes in the last
I have a table (natomr) with 200 records which defines different areas. I want
I have a partitioned table that belongs to tablespace report . I want to

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.