Solved

MySQL Query - select all records with this month and year

Posted on 2008-10-28
3
1,559 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Creating and Managing Databases with phpMyAdmin in cPanel.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

839 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