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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:49:08+00:00 2026-06-18T08:49:08+00:00

I am trying to check for all records that occurred last month using the

  • 0

I am trying to check for all records that occurred last month using the following statement.

Select  *  from statistics 
where statistics_date  
BETWEEN date_format(NOW() - INTERVAL 1 MONTH, '%Y-%m-01') 
AND last_day(NOW() - INTERVAL 1 MONTH ) 

However, the selection does not include the last day. What I want is from the first second of the month until the last second of the month.

  • 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-18T08:49:09+00:00Added an answer on June 18, 2026 at 8:49 am

    BETWEEN is notoriously bad for date and timestamp work because it gets the end date wrong.

    Here’s what you need:

    First, let’s compute the first day of the present month. You had that exactly right.

     DATE_FORMAT(NOW(),'%Y-%m-01')
    

    Next, let’s compute the first day of last month:

     DATE_FORMAT(NOW(),'%Y-%m-01') - INTERVAL 1 MONTH
    

    Now, we select the records that lie in the interval.

    Select * 
      from statistics 
     where statistics_date   >=   DATE_FORMAT(NOW(),'%Y-%m-01') - INTERVAL 1 MONTH
       and statistics_date   <    DATE_FORMAT(NOW(),'%Y-%m-01')
    

    Do you see how the beginning of the date range is chosen with >= and the end with <? Do you see how I used the first day of the present month for the end of the date range? Those things are important, because timestamps can have days and times in them. Consider the timestamp ‘2013-01-31 23:58’. It happens to be after ‘2012-01-31’ so between won’t catch it.

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

Sidebar

Related Questions

trying to add a sub query that only shows records from the last calendar
I am trying to check the following and all throw an out of bounds
I am trying to get all records that are tied to a parent object
I'm trying to select values from a database, but I need to check another
I am trying to check all the checkboxes on a webform (aspx) page, which
The thing I'm trying is to check all those checkboxes, when "cbkomplet" is checked.
I'm having a problem trying to create a Javascript function that checks all the
I'm trying to check a checkbox, i've tried doing the following :- $('#someId').attr('checked','checked'); $('#someId').attr('checked',
Hey all i am trying to populate my query with all the records in
I'm getting strange behavior when trying to select from a hash created with group_by

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.