| | |
Extracting Month and day from datetime..
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2009
Posts: 3
Reputation:
Solved Threads: 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:
****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??
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:
sql Syntax (Toggle Plain Text)
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??
Last edited by Ezzaral; Jul 7th, 2009 at 5:03 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
•
•
Join Date: Aug 2007
Posts: 165
Reputation:
Solved Threads: 18
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.
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.
•
•
Join Date: Aug 2007
Posts: 5
Reputation:
Solved Threads: 0
sql Syntax (Toggle Plain Text)
SELECT * FROM <tn> WHERE YEAR(date_mem)='yyyy';
Last edited by peter_budo; Aug 27th, 2009 at 11:23 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
![]() |
Similar Threads
- Datetime conversion (C#)
- DateTime field - How do I assign a time other than current? (VB.NET)
- how to get day, month and year (JSP)
- Current month name (ASP.NET)
- Getting first day of the month (ASP.NET)
- day month year help (C++)
- Day of Week (Python)
- Logic to Convert Days From 1800 to a Date (Month, Day, Year) (C++)
Other Threads in the MySQL Forum
- Previous Thread: Optimize SQL
- Next Thread: Need Help with SQL.. ORA00933
Views: 1017 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for MySQL
1 agplv3 alfresco api artisticlicense aws bizspark breathalyzer camparingtocolumns cmg communityjournalism contentmanagement contractors copyright count court data database design developer development distinct drupal dui ec2 eliminate email enter enterprise error eudora facebook form foss gnu government gpl greenit hiring hyperic images innerjoins insert ip joebrockmeier join keyword keywords kickfire law legal license licensing maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange montywidenius multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle pdf penelope php query referencedesign reorderingcolumns resultset saas search select sharepoint simpledb sourcecode spotify sql statement sugarcrm syntax techsupport thunderbird transparency update virtualization





