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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:17:43+00:00 2026-06-18T03:17:43+00:00

I need to get last six month values from the database. Here is my

  • 0

I need to get last six month values from the database. Here is my Fiddle. I need to get the values dynamically. Now February. So I need August to January values from database. If March then the values should automatically change to October to February. So the thing I need to get last six month values.

My Code follows.

CREATE TABLE IF NOT EXISTS `ratepersqft` (
  `price_id` int(11) NOT NULL auto_increment,
  `project_id` int(11) default NULL,
  `date` varchar(255) default NULL,
  `rate_per_sqft` double default NULL,
  `common_location` varchar(255) default NULL,
  PRIMARY KEY  (`price_id`)
); 

INSERT INTO `ratepersqft` (`price_id`, `project_id`, `date`, `rate_per_sqft`, `common_location`) VALUES
    (1, 1, '2012-07-01 ', 2800, 'ECR'),
    (2, 2, '2012-07-02 ', 1550, 'ECR'),
    (3, 3, '2012-07-03 ', 1850, 'ECR'),
    (4, 4, '2012-07-04 ', 4425, 'ECR'),
    (5, 5, '2012-07-05 ', 2300, 'ECR'),
    (6, 1, '2012-08-01 ', 2900, 'ECR'),
    (7, 2, '2012-08-02 ', 1650, 'ECR'),
    (8, 3, '2012-08-03 ', 1950, 'ECR'),
    (9, 4, '2012-08-04 ', 4525, 'ECR'),
    (10, 5, '2012-08-05 ', 2200, 'ECR'),
    (11, 1, '2012-09-01 ', 3000, 'ECR'),
    (12, 2, '2012-09-02 ', 1450, 'ECR'),
    (13, 3, '2012-09-03 ', 2050, 'ECR'),
    (14, 4, '2012-09-04 ', 4625, 'ECR'),
    (15, 5, '2012-09-05 ', 2100, 'ECR'),
    (16, 1, '2012-10-01 ', 3100, 'ECR'),
    (17, 2, '2012-10-02 ', 2150, 'ECR'),
    (18, 3, '2012-10-03 ', 1850, 'ECR'),
    (19, 4, '2012-10-04 ', 4725, 'ECR'),
    (20, 5, '2012-10-05 ', 1900, 'ECR'),
    (21, 1, '2012-11-01 ', 3200, 'ECR'),
    (22, 2, '2012-11-02 ', 2250, 'ECR'),
    (23, 3, '2012-11-03 ', 1850, 'ECR'),
    (24, 4, '2012-11-04 ', 4825, 'ECR'),
    (25, 5, '2012-11-05 ', 2300, 'ECR'),
    (26, 1, '2012-12-01 ', 3300, 'ECR'),
    (27, 2, '2012-12-02 ', 2350, 'ECR'),
    (28, 3, '2012-12-03 ', 1850, 'ECR'),
    (29, 4, '2012-12-04 ', 4925, 'ECR'),
    (30, 5, '2012-12-05 ', 2400, 'ECR'),
    (31, 1, '2013-01-01 ', 3400, 'ECR'),
    (32, 2, '2013-01-02 ', 2000, 'ECR'),
    (33, 3, '2013-01-03 ', 2450, 'ECR'),
    (34, 4, '2013-01-04 ', 5025, 'ECR'),
    (35, 5, '2013-01-05 ', 2500, 'ECR'),
    (36, 1, '2013-02-01 ', 3500, 'ECR'),
    (37, 2, '2013-02-02 ', 2100, 'ECR'),
    (38, 3, '2013-02-03 ', 2550, 'ECR'),
    (39, 4, '2013-02-04 ', 5125, 'ECR'),
    (40, 5, '2013-02-05 ', 2600, 'ECR'),
    (41, 1, '2012-06-01 ', 1800, 'ECR'),
    (42, 2, '2012-06-02 ', 1150, 'ECR'),
    (43, 3, '2012-06-03 ', 1350, 'ECR'),
    (44, 4, '2012-06-04 ', 3425, 'ECR'),
    (45, 5, '2012-06-05 ', 2100, 'ECR');

I am trying this query and it give me all the values in the Database.

SELECT *
  FROM ratepersqft
 WHERE MONTH(date) < DATE_SUB(CURDATE(), INTERVAL 6 MONTH)

Hope my question is clear. Thanks in Advance!!!

  • 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-18T03:17:44+00:00Added an answer on June 18, 2026 at 3:17 am

    For MYSQL: you may use date_add:

     SELECT * FROM ratepersqft 
    WHERE date < Now() and date > DATE_ADD(Now(), INTERVAL- 6 MONTH);
    

    For SQL Server:, dateadd :

      SELECT * FROM ratepersqft 
     WHERE date < Now() and date > DATEADD(Month, -6, Now());
    

    http://www.sqlfiddle.com/#!2/1f8029/48

    **Please wrap your date column name with backticks given it is a reserved key word. **

    MYSQL update:

    SQLFIDDLE DEMO

    SELECT *
    FROM ratepersqft 
    WHERE date_format(date,'%Y-%m') < 
                         date_format(now(),'%Y-%m')
    and date_format(date,'%Y-%m') >= 
                         date_format(now() - interval 6 month,'%Y-%m')
    order by date desc;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here i need to get the last value from a model list in a
I need to get the last day of the month given as a date
I need to get the story_id from the last insert. Ive tried using mysql_insert_id()
I have 4 Tables (listed bellow) and need: get last 10 Chats from Room
I need to get the last part of current directory, for example from /Users/smcho/filegen_from_directory/AIRPassthrough
I need to get the last 2 characters from the href of a link
I need to get the last X rows from a table, but in order
I need to get only the 2nd from last digit from the ui.value on
I need to get last record from db. I'm using sqlalchemy. At the moment,
I have a mysql query. I need to get last value from columns Lat,Lng

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.