1

我试图通过匹配当前日期来显示当前生日。Mysql 日期格式是 1990 年 9 月 16 日,所以我从当前日期修剪了年份并回显 16 Sep,现在如何回显,如果当前日期等于行中的日期。我尝试了下面的方法,这是一个错误。

$timezone = new DateTimeZone("Asia/Kolkata" );
$date = new DateTime();
$date->setTimezone($timezone );
$date2= $date->format( 'd M' );
$date4=date('d M', strtotime($date2));


<?php $sel = $db->query("select * from mov_birthday where date('d M', strtotime(dateofb)) == '$date4' order by dateofb"); 

while($row=mysql_fetch_array($sel)){

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

1 回答 1

1

您可以使用like

// this will select every date that starts with date('d M') - day Month
$timezone = new DateTimeZone("Asia/Kolkata" );
$date = new DateTime();
$date->setTimezone($timezone);
$dateFormat = $date->format( 'd F' );
$sel = $db->query("SELECT * FROM `mov_birthday` where `dateofb` LIKE '".$dateFormat."%' ORDER BY `dateofb`");
while($row = $sel->fetch(PDO::FETCH_ASSOC)) {
    echo $row['name'];
}
于 2012-09-15T21:09:11.717 回答