我有一个用户表,其中包含用户的dob现在我只想从该列中提取月份和日期,以便我可以通过jgrowl发送生日通知。
我该怎么做?我正在使用MySql并使用Date作为出生日期的类型......
这好吗? ::
public function actionBirthday(){
$user = Query::queryOne("SELECT MONTH(date_of_birth) AS birthmonth, DAY(date_of_birth) AS birthday FROM user");
// $date = date('m-d');
if($user['birthmonth'] == date('m') && $user['birthday'] == date('d')) {
if (Yii::$app->session['user_jSN4h1wSYC7D6JFOwh6M']['role'] != Yii::$app->params['user_role']['superadmin']) {
$log = array(
'content' => "Today is " . ucfirst(Yii::$app->session['user_jSN4h1wSYC7D6JFOwh6M']->username) . "Birthday",
'type' => "user"
);
Notify::sendNotification($log);
}
}
}
答案 0 :(得分:1)
试试这个:
select DATE(date_of_birth) as date, MONTH(date_of_birth) as month from table where column = value;
// date() will extract date and month() will extract month from date of birth column