Date Comparision in PHP and my sql
i want to compare database field of date that has YYYY-MM-DD
format and i want to compare from MM-DD
actually i want to fetch records those have birthdays between month开发者_运维问答 /selected week durations
and birthdate is stores as YYYY-MM-DD format in db table
how can i achieve this kindly help.
Look at this:
http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html
you can use CURDATE(), DATE_ADD() and DATE_SUB() to make date interval
Within your sql you could try something like the following:
select * from people where birthdate>='10/01/2010' AND birthdate<='30/01/2010';
if you want to get more specific with months and days then you can utilise the month(birthdate)
and day(birthdate)
functions in mysql;
select * from people where month(birthdate)=10;
would return all your people where the month for birthdate is October.
精彩评论