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

  • Home
  • SEARCH
  • 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 8641351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:30:17+00:00 2026-06-12T11:30:17+00:00

I want to get records between to date from mysql database. I wrote this

  • 0

I want to get records between to date from mysql database. I wrote this but it does not work :

$from_date = "2012-06-19";
$to_date = "2012-06-24";

SELECT * 
  FROM `contracts` 
 WHERE `indate` >= '$from_date' 
   AND `indate` <= '$to_date' 
 ORDER BY `id` DESC

My dates are : 2012-06-20 , 2012-06-21 , 2012-06-22 , 2012-06-23

  • 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-12T11:30:18+00:00Added an answer on June 12, 2026 at 11:30 am

    What you’re doing should work fine. I select from date fields like this all the time at work.

    mysql> create table contracts (indate date);
    Query OK, 0 rows affected (0.02 sec)
    
    mysql> insert into contracts values ('2012-10-06'), ('2012-11-04'), ('2012-09-17');
    Query OK, 3 rows affected (0.00 sec)
    Records: 3  Duplicates: 0  Warnings: 0
    
    mysql> set @from_date = '2012-10-01';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> set @to_date = '2012-10-31';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> select * from contracts where indate >= @from_date and indate <= @to_date;
    +------------+
    | indate     |
    +------------+
    | 2012-10-06 |
    +------------+
    1 row in set (0.00 sec)
    

    I used mysql variables here of course, but there’s nothing to them; they just contain strings. You could do this instead:

    mysql> select * from contracts where indate >= '2012-10-01' and indate <= '2012-10-31';
    +------------+
    | indate     |
    +------------+
    | 2012-10-06 |
    +------------+
    1 row in set (0.00 sec)
    

    The O.P. are right though, BETWEEN is much more succinct:

    mysql> select * from contracts where indate between '2012-10-01' and  '2012-10-31';
    +------------+
    | indate     |
    +------------+
    | 2012-10-06 |
    +------------+
    1 row in set (0.00 sec)
    

    The magic of the date comparison is because the field is of date type.

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

Sidebar

Related Questions

I want to use this SQL query to get only the records between 8
I want to get the records of last month based on my database table
I want to get all the records from the one table which contain at
I have two employee lists that I want to get only unique records from
I have a database with >100K records and I want to get the results
Suppose you want to get a record from database which returns a large amount
I want to fetch records that fall between the two timestamp. I want this
I want to get only status = 1 records. But I don't have status
I want to get the data between a date. Am having some record with
I want to limit a report to return records from Date A through Date

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.