user2352034
user2352034

Reputation: 55

Select all data from current month and next month from MYSQL database

I cant figure out how to make this work, i tried a lot of different ways but i didn't found working one, so please help me :)

my current query looks like:

SELECT * FROM `police` 
WHERE skadenca BETWEEN DATE(now()) 
  AND adddate(current_date, interval +1 month) 
  AND produkt LIKE 'avto' 
  AND statusobnove=0 AND status=0

so just like i already said i want to grab all data from current month and next month.

ty

Upvotes: 0

Views: 1793

Answers (1)

GMB
GMB

Reputation: 222402

There is more than one way to understand your question.

Between current date and end of next month would phrase as:

where 
    skadenca >= current_date 
    and skadenca < date_format(current_date, '%Y-%m-01') + interval 2 month

Between the start of current month and the end of next month would be:

where 
    skadenca >= date_format(current_date, '%Y-%m-01')
    and skadenca < date_format(current_date, '%Y-%m-01') + interval 2 month

Between the current date and one month ahead would be:

where 
    skadenca >= current_date
    and skadenca < current_date + interval 1 month

Upvotes: 2

Related Questions