0

Hi.. I'm trying to extract the day, month, and year from a datetime to use it within a 'WHERE' statement.

Table: workshops
workshopid - int(10)
workshopgroupcoursecode - text
title - varchar(255)
description - text

Table: workshops
workshopscheduleid - int(10)
workshopid - int(10)
startdatetime - datetime
enddatetime - datetime
timedescription - text

Query:

SELECT workshops.workshopid, EXTRACT(DAY FROM workshopschedules.startdatetime) as d, workshops.title,
FROM workshopschedules,  workshops
WHERE Month(workshopschedules.startdatetime) = '$month' AND Year(workshopschedules.startdatetime) = '$year'";

****You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM workshopschedules, workshops WHERE Month(workshopsched

does mysql not allow me to extract the day and month and use it in a WHERE condition??

4
Contributors
4
Replies
14
Views
8 Years
Discussion Span
Last Post by guruparthi
0

It's telling you exactly where to look for the error. Hint: look at the first non-whitespace character before 'FROM'.

Give up? OK. You have a trailing comma in your AS clause. (You've no idea how many times I've hit this in the past 7 years just from editting a script or a schema.) Otherwise, the syntax looks OK.

When the error says to look 'near', it usually means to look before. In time and with practice, your brain will learn to grok what your eye is seeing. :) :)

-1
select * from table where DATE(field)='yyyy-mm-dd'
Votes + Comments
dude, its four years old, the op has left the building, and by the way, your answer is wrong,
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.