HI all...
I have a small problem here ...
I have a table and a date field and it is stored in the format as 'YYYY-MM-DD'.
Now i want to retrieve the rows between some date .Like
select * from table_name where date >='2006-12-22' and date<='2008-02-22'
up to now i had successfully done this job but i dont want the date results ...
it is giving the all results.I want only year and month results.Please help how to do this
is there any function in mysql like date>='2007-12-%'
The % should compare with any of the date within that month
Please help
Thanks in Advance...
Problem with date in Mysql
Moderator: General Moderators
Re: Problem with date in Mysql
what your looking for is this
[sql] SELECT * FROM `table_name` WHERE date LIKE '2006-12-%'; [/sql]
% is use as a wild card.
Note: use SQL tags on your code next time
[sql] SELECT * FROM `table_name` WHERE date LIKE '2006-12-%'; [/sql]
% is use as a wild card.
Note: use SQL tags on your code next time
- Sekka
- Forum Commoner
- Posts: 91
- Joined: Mon Feb 18, 2008 10:25 am
- Location: Huddersfield, West Yorkshire, UK
Re: Problem with date in Mysql
Or you may need DATE_FORMAT(). E.g.
[sql]SELECT * FROM mytable WHERE DATE_FORMAT(date,'%Y-%m') >= '2007-12'[/sql]
[sql]SELECT * FROM mytable WHERE DATE_FORMAT(date,'%Y-%m') >= '2007-12'[/sql]
Re: Problem with date in Mysql
I never knew there was such a function :O
-
rams_iridium
- Forum Newbie
- Posts: 2
- Joined: Tue Mar 11, 2008 4:00 am
Re: Problem with date in Mysql
Thank you soo much the problem has been solve.Thanks again ...