954,164 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Extracting Month and day from datetime..

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??

dopeynite
Newbie Poster
3 posts since Jan 2009
Reputation Points: 10
Solved Threads: 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. :) :)

Fest3er
Posting Whiz in Training
242 posts since Aug 2007
Reputation Points: 51
Solved Threads: 35
 

thank-you.... =D

dopeynite
Newbie Poster
3 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 
select * from <tn> where year(date_mem)='yyyy';
gaurav252
Newbie Poster
5 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You