Jump to content


Problem with mysql YEAR_MONTH

  • Please log in to reply
2 replies to this topic

#1 delamitri

  • New Members
  • Pip
  • Newbie
  • 7 posts
  • LocationUK

Posted 08 January 2003 - 02:39 PM

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:


but get a mysql error.


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


#2 pallevillesen

  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 09 January 2003 - 10:43 AM

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)



P., denmark
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center

#3 delamitri

  • New Members
  • Pip
  • Newbie
  • 7 posts
  • LocationUK

Posted 09 January 2003 - 11:47 AM

hmm, entering this into phpmyadmin causes it to fall over.

When I type the query below, it does something very strange!!

SELECT * FROM reservations WHERE extract(year_month FROM date_departure) = extract(year_month FROM \'2002-12-02\')

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users