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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting month

Status
Not open for further replies.

buzzt

Programmer
Joined
Oct 17, 2002
Messages
171
Location
CA
I have a column in my MySQL table which has dates (in the date column)in a yyy-mm-dd format. I need to use PHP to locate any data with whose month is the same as the current month. (All entries from 2003-09-01, to 2003-09-30 would be displayed).

What is the best way? How do I write the query?
 
I think I got it.

select * from table where month(date_col)=month(curdate());

 
Use PHP to fetch the current month and year. Something like:

list ($year, $month) = (explode (':', date('Y:m')));

Then I would use those two values to construct a query of the form:

SELECT .... FROM ....
WHERE month(datecolumn) = $month and year(datecolumn) = $year



Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top