Solved

MySQL Query - select all records with this month and year

Posted on 2008-10-28
3
1,562 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

Accepted Solution

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

Expert Comment

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

Expert Comment

by:hielo
ID: 22822497
glad to help
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

691 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