Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

MySQL Query WHERE MONTH

I am trying to create a query that SELECTS data out of a DB the has a date equal to the current month.  The following query fails at: WHERE MONTH('date') = MONTH(CURDATE()) AND

	$sql->query("SELECT doctor_doctor.doctor_id, doctor_doctor.first_name AS first_name, doctor_doctor.last_name AS last_name, doctor_schedule.doctor_id, doctor_schedule.schedule_date AS date, doctor_schedule.time AS time, doctor_schedule.location_id
	FROM doctor_doctor, doctor_schedule
	WHERE MONTH('date') = MONTH(CURDATE()) AND doctor_doctor.doctor='1' AND doctor_doctor.doctor_id=doctor_schedule.doctor_id AND doctor_schedule.location_id='1' 
	ORDER BY date DESC");

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of David Kroll
David Kroll
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Robert Granlund

ASKER

@dkrollCTN Do you have any idea how I would write it so I can advance it, one month at a time?
You can do:

WHERE MONTH(doctor_schedule.schedule_date)  = MONTH(CURDATE()) + 1

Not sure if that's what you're asking
The query shows the current month but Id like to incorporate a "Next Month" and Prev Month" Button but I'm not sure were to start
Next month would be
WHERE MONTH(doctor_schedule.schedule_date)  = MONTH(CURDATE()) + 1

prev month

WHERE MONTH(doctor_schedule.schedule_date)  = MONTH(CURDATE()) - 1