0

我已经在论坛中搜索了适当的代码,或者是否有任何解决方案但还没有。我的数据库中有这个 varchar 12-03-1994 (dmY),我的代码选择了该年龄范围内的用户数。我需要将 varchar 中的 date_of_birth 转换为 date_format 并且我使用了 str_to_date 所以我这样做了,但是 kip 得到了一个空的结果。我究竟做错了什么?

$aged = $conn->prepare("SELECT COUNT(STR_TO_DATE('date_of_birth','%d-%m-%Y')) as year FROM tbl_members WHERE date_of_birth BETWEEN CURDATE() - INTERVAL 105 YEAR AND 
    CURDATE() - INTERVAL 36 YEAR AND resultselect = ?");
$aged->execute(array($pid));
$recordaged = $aged->fetchObject();
$recorda = $recordaged->year;
4

1 回答 1

0

好的,我没有任何东西可以测试它,但看起来它可以工作......

// needs variables $conn and $pid
$aged = $conn->prepare("SELECT STR_TO_DATE('date_of_birth','%d-%m-%Y') as converted_date FROM tbl_members WHERE converted_date BETWEEN CURDATE() - INTERVAL 105 YEAR AND CURDATE() - INTERVAL 36 YEAR AND resultselect = ?");
$result = $aged->execute(array($pid));
$count = mysql_num_rows($result);
于 2013-11-15T17:44:29.563 回答