Solved

MySQL Query - select all records with this month and year

Posted on 2008-10-28
3
1,550 Views
Last Modified: 2013-12-13
Hello,

I'm trying to make a mysql query that will take $month and $year variables and select all record in a MySQL database whose 'date' field is "$year-$month-*"

How would I do this?
0
Comment
Question by:Mr_Splash
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 300 total points
Comment Utility
mysql_query("SELECT * FROM Table WHERE DATE_FORMAT(`date`,'%Y-%m') = '$year-$m'") or die(mysql_error());
0
 
LVL 5

Expert Comment

by:ionutz2k2
Comment Utility
or
mysql_query("select * from Table where (Month(DateField) = ".$month.") and (Year(DateField) = ".$year.")");
0
 
LVL 82

Expert Comment

by:hielo
Comment Utility
glad to help
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now