Jump to content

Problem finding agenda events of a certain month/year


Recommended Posts

Hi there!

I've a table for events with the following structure

 

TABLE events

 

id

date_begin

date_end

 

I'm having problems to find a query that can list me the events for a certain month/year

 

ex: i want to call a php function with params (month, year) to obtain the matched events

getEventsByMonth($month,$year)

 

thx in advance

 

MySql 5.0.67-community;    PHP version-5.2.9

 

The current query i have is

 

$query = "SELECT * FROM eventos WHERE status='0' AND MONTH(date_begin)<='$month' AND YEAR(date_end)<='$year' AND MONTH(date_begin)>='$month' AND YEAR(date_end)>='$year'";

 

but it doesn't work for all the cases

If your trying to list events for a specific MONTH and YEAR, why are you checking if the month of the date_begin is before or equal to and after or equal to, shouldn't you just be checking if it's equal? If I was to hazard a guess based on your description I'd have thought your after.

 

$query = "
SELECT * FROM eventos 
WHERE status='0' 
AND (MONTH(date_begin)='$month' OR MONTH(date_end)='$month') 
AND (YEAR(date_begin)='$year' OR YEAR(date_end)='$year')";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.