Jump to content

Recommended Posts

Hi all,

 

I have a problem with the YEAR_MONTH query in mysql, which is very bizzarre.

 

Having read the date/time functions on the mysql site, they say using YEAR_MONTH extracts the year an month from a given date field

 

a simple query should work:

 

SELECT YEAR_MONTH(CURDATE());

 

but get a mysql error.

 

tried

 

SELECT MONTH(CURDATE()) and also SELECT YEAR(CURDATE()) which both work fine, but just cannot use this YEAR_MONTH option.

 

I am using mysql 3.23.47, is this YEAR_MONTH thing not in this version or am I just doing something totally wrong here?

 

BTW even tried replacing CURDATE with NOW() and also a manual input of \'2002-12-22\', but all come up with the same error

 

Kevin

Link to comment
https://forums.phpfreaks.com/topic/27-problem-with-mysql-year_month/
Share on other sites

It exists but your syntax is wrong.

 


mysql> select extract(year_month FROM curdate());

+------------------------------------+

| extract(year_month FROM curdate()) |

+------------------------------------+

|                             200301 |

+------------------------------------+

1 row in set (0.00 sec)



mysql> 

mysql> 

 

P., denmark

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.