Page 1 of 1

Extracting month from datetime data type

Posted: Sat Oct 25, 2003 7:48 am
by devork
I know that it is very easy, have done it by some how
is there any easy to extract month from datetime
2003-01-01 01:01:02
the thing that I want to do is extract the records that are specific
month
select * from table where datetime_column=MONTH('2003-01-02')

Posted: Sat Oct 25, 2003 10:26 am
by cybaf
you can do this:

Code: Select all

select * from table where SUBSTRING(datetime_column,6,2)=MONTH('2003-01-02');
have a look at http://www.mysql.com/doc/en/String_functions.html for further details

Posted: Sat Oct 25, 2003 10:32 am
by cybaf
or just

Code: Select all

select * from table where MONTH(datetime_column)=MONTH('2003-01-02');
:)

problem resolved some how

Posted: Sat Oct 25, 2003 12:14 pm
by devork
cybaf wrote:or just

Code: Select all

select * from table where MONTH(datetime_column)=MONTH('2003-01-02');
:)
first one is working [how i forgot that]
second one is returning NULL
thanx by the way

Posted: Sat Oct 25, 2003 7:29 pm
by cybaf
that's strange... I just tried it again on my server and it worked nicely...

well well the first one worked so...:)