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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:53:43+00:00 2026-05-30T23:53:43+00:00

Normally if I want to make a query on a table by date range

  • 0

Normally if I want to make a query on a table by date range I’ll do it this way:

SELECT DISTINCT c.ID AS 'id' FROM CUST c 
JOIN TICKET t ON s.ID = t.SALE_ID 
WHERE c.ACTIVE_IND = 1 
AND t.DELIV_DATE BETWEEN '01-01-2012' AND '01-02-2012'
ORDER BY t.DELIV_DATE DESC

Now I need to make the same query but ignore the year, so I can say from February 28 to March 2 and year doesn’t matter.

I tried modifying the query:

SELECT DISTINCT c.ID AS 'id' FROM CUST c 
JOIN TICKET t ON s.ID = t.SALE_ID 
WHERE c.ACTIVE_IND = 1 
AND MONTH(t.DELIV_DATE) BETWEEN  ... AND ... 
AND DAY(t.DELIV_DATE) ... BETWEEN ...
ORDER BY t.DELIV_DATE DESC 

Above query works fine if the starting DAY is smaller than the ending. that means if I go from lets say Feb 20 to Feb 28 it works fine but if I go with Feb 28 to Mar 2 it won’t work.

Any solution for this that I can make this happen in a single query ?

  • 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-30T23:53:44+00:00Added an answer on May 30, 2026 at 11:53 pm
    ...
    AND DATE_FORMAT(t.DELIV_DATE, '%m%d') BETWEEN '0101' AND '0201'
    ...
    

    Update – to handle range that loops though the end year (replace 0101 and 0201 with actual variables representing from and to):

    ...
    AND
      (DATE_FORMAT(t.DELIV_DATE, '%m%d') BETWEEN '0101' AND '0201'
       OR '0101' > '0201' AND
         (DATE_FORMAT(t.DELIV_DATE, '%m%d') >= '0101' OR
          DATE_FORMAT(t.DELIV_DATE, '%m%d') <= '0201'
         )
      )
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Normally I make something like this. #1 first query while () : #2 2nd
I'm sick of this. ALWAYS when I make a HTTP GET query from a
Normally you can do this: <select size=3> <option>blah</option> <option>blah</option> <option>blah</option> </select> And it would
i want to make a personal image, that shows the last 3 items from
I guess, normally people would be aiming to make their programme behave like this,
I want to make a function, like this. For example: function Logger() { this.log
I have a query that selects all the information from a database table and
I have a ridiculous question due to a ridiculous problem. Normally if I want
Normally, when I want to allow a user to download a file without revealing
Normally my URLs look like the standard: www.example.com/controller/action Now I want to setup my

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.