如何使用mysql显示即将到来的生日?

时间:2012-09-03 20:16:16

标签: php mysql

我想在我的网站上显示未来的生日,所以使用出生日期订购它们(dateofb) 以下查询未显示dateofb命令中的bateof births。它使用id。

按顺序显示

“dateofb包含1970年9月20日格式的出生日期。”

<?php $sel = $db->query("select * from mov_biography order by dateofb asc limit 0,5"); 
while($row=mysql_fetch_array($sel)){

echo ($row['name']); } ?>

2 个答案:

答案 0 :(得分:0)

你可以做那样的事......

SELECT

  , MONTH(dateofb)  AS month
  , DAY(dateofb ) AS day  

FROM <table_name>
WHERE  birthday BETWEEN NOW() AND DATE_ADD(NOW, INTERVAL 90 DAY)  
ORDER BY Birthday DESC

答案 1 :(得分:0)

使用默认排序,它看起来如下所示:

mysql> SELECT column FROM table_name ORDER BY column; 

column
======
100
1000
10000
200
2000
20000
...

Now with "... ORDER BY column+0", I get it sorted right:

mysql> SELECT column FROM table_name ORDER BY column+0; 

column
======
100
200
1000
2000
10000
20000
...

This is a quick fix instead of sorting to CAST operator.