Reputation: 5158
SELECT WEEK(STR_TO_DATE( products_options_values, '%m-%d-%Y' ),1) as order_week,
YEAR(STR_TO_DATE( products_options_values, '%m-%d-%Y' ),1) as order_year
FROM orders_products_attributes
If it's just the week I don't get any error, but as soon as I try to select the year as well, it throws
1064 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 '1) as order_year FROM orders_products_attributes'...
What am I doing wrong?
Upvotes: 0
Views: 82
Reputation: 1
Improper use of YEAR()
method. second paramater should not be there.
Try this one:
SELECT WEEK(STR_TO_DATE( products_options_values, '%m-%d-%Y' ),1)
as order_week,
YEAR(STR_TO_DATE( products_options_values, '%m-%d-%Y' )) as order_year
FROM orders_products_attributes
Upvotes: 0
Reputation: 1872
use this sql
SELECT WEEK(STR_TO_DATE( products_options_values, '%m-%d-%Y' ),1) as order_week,
YEAR(STR_TO_DATE( products_options_values, '%m-%d-%Y' )) as order_year
FROM orders_products_attributes
for further reading http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_year
Upvotes: 0
Reputation: 204746
Replace
YEAR(STR_TO_DATE( products_options_values, '%m-%d-%Y' ),1)
with
YEAR(STR_TO_DATE( products_options_values, '%m-%d-%Y' ))
There is no second parameter for the YEAR()
function. Or you could just do
STR_TO_DATE( products_options_values, '%Y' )
Upvotes: 1