Selecting Month from SQL Date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
foxtamerind
Forum Newbie
Posts: 3
Joined: Mon Sep 20, 2010 9:46 am

Selecting Month from SQL Date

Post by foxtamerind »

I set up a database with phpMyAdmin where I have a table called "matches". A row inside the table called "match_date" uses the little date calendar thing to select a date. In my php Query I want it only to select the entries that have the current month. What should my $query look like to do such a thing?

Currently it looks like:

$query = "SELECT * FROM matches"
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Selecting Month from SQL Date

Post by pickle »

What's the format of the date field in your database? The easiest thing would be to update your "little calendar thing" to store the date in the MySQL DATE format. You could then use the MySQL MONTH() function.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply