Solved

MySQL Query - select all records with this month and year

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with mod_substitute 18 44
What is this? I've never seen this... 2 29
Length of for loop to be dynamic 2 33
Convert php array to comma seperated list 19 35
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 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