SELECT * FROM users__accounts WHERE DATE_FORMAT(birthday, '%m%d' ) >= '0901' AND DATE_FORMAT(birthday, '%m%d' ) <= '1029'
* This source code was highlighted with Source Code Highlighter .
SET @dayplus:=15;
SET @andor:= CASE WHEN YEAR (CURDATE() + INTERVAL @dayplus DAY ) - YEAR (CURDATE()) THEN 'OR' ELSE 'AND' END ;
SET @fromdate:=DATE_FORMAT(CURDATE(), '%m%d' );
SET @todate:=DATE_FORMAT(CURDATE() + INTERVAL @dayplus DAY , '%m%d' );
SET @birthday_query:=CONCAT(" SELECT * FROM users__accounts WHERE DATE_FORMAT(birthday, '%m%d' ) >= @fromdate ",
@andor, " DATE_FORMAT(birthday, '%m%d' ) <= @todate");
PREPARE birthday_query FROM @birthday_query;
EXECUTE birthday_query;
DEALLOCATE PREPARE archive_query;
* This source code was highlighted with Source Code Highlighter .
class Users extends Zend_Db_Table_Abstract
{
protected $_name = 'users__accounts' ;
/**
...
*/
public function getBirthdayUsers($count, $days = 7)
{
$date = new Zend_Date();
/* */
$dateFrom = $date->toString( 'MMdd' );
/* ;) */
if ($dateFrom == '0301' && !$date->isLeapYear()) {
$dateFrom = '0229' ;
}
$yearFrom = $date->toString( 'YY' );
$date->addDay($days);
/* + $days */
$dateTo = $date->toString( 'MMdd' );
$nextYear = $yearFrom - $date->toString( 'YY' );
$select = $ this ->getAdapter()->select()
->from(array( 'u' => $ this ->_name))
->where( "date_format(u.birthday,'%m%d') >= ?" , $dateFrom)
->order( 'DAYOFYEAR(u.birthday)' )
->limit($count);
/* - OR / AND */
if ($nextYear == 0) {
$select->where( "date_format(u.birthday,'%m%d') < ?" , $dateTo);
} else {
$select->orWhere( "date_format(u.birthday,'%m%d') < ?" , $dateTo);
}
$users = $select->query()->fetchAll();
return $users;
}
}
* This source code was highlighted with Source Code Highlighter .
/**
* @param timestamp() $birth
* @return INT
*/
function getAge($birth)
{
$now = time();
$age = date( 'Y' , $now) - date( 'Y' , $birth);
if (date( 'md' , $now) < date( 'md' , $birth)) {
$age--;
}
return $age;
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/62853/
All Articles