Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Current Moth

Status
Not open for further replies.

frankienstien

Programmer
Apr 12, 2006
8
US
i need to be able to select all the items in the database that are in the current month.
or
i need to be able to select all the items that are within 30 days of todays date.

this is for a nursery school that would like to be able to show the lunch menu's for the month.

the table is very simple

tblMenu

ID autoincrement
LunchDate Date
LunchItem Text

Thank you for your help.
 
You are looking for the Month function to sort out the month and the Date function to get the current date. Try this
Code:
Select LunchDate, LunchText from tblMenu Where Month(LunchDate) = Month(Date)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
You need to take the year into account, and also the current date:
[tt]
where EXTRACT(YEAR_MONTH FROM lunchdate) = EXTRACT(YEAR_MONTH FROM CURRENT_DATE)
[/tt]
 
select whatever from table where your_date >= date_sub(curdate(), interval 30 days);

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
whoops .. mod that to date_add


______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
bah why isnt there an edit.

ok take 3.

select blah from yourtable where your_date >= curdate() AND yourdate <= date_add(curdate(), interval 30 day);

Hopefully my confusion has ended.
Code:
mysql> select curdate();
+------------+
| curdate()  |
+------------+
| 2006-08-28 |
+------------+
1 row in set (0.00 sec)
mysql> select date_add(curdate(), interval 30 day);
+--------------------------------------+
| date_add(curdate(), interval 30 day) |
+--------------------------------------+
| 2006-09-27                           |
+--------------------------------------+
1 row in set (0.00 sec)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
sorry my internet's been down for a little while cable got cut by city crew (go figure)
this is my current code, not pretty yet but i'm working on it.

Code:
"SELECT * FROM tblMenu WHERE MONTH(LunchDay) = MONTH(DATE_ADD(NOW(), INTERVAL 0 MONTH)) ORDER BY LunchDay DESC"

let me know if you see anything wrong with it.

thanx for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top