一个想法是从日期中提取: 年、月、日。然后
$qb->select( p )
->where( YEAR(p.postDate) = :year )
->andWhere( MONTH(p.postDate) = :month )
->andWhere( DAY(p.postDate) = :day );
$qb->setParameter( year , $year)
->setParameter( month , $month)
->setParameter( day , $day);
周一和一年 你取出理论的扩展
例如:
< a href=>"https://github.com/simukti/DoctrineExtensions" rel=“noreferrer>>DoctrineExtensions
这对我有用,你只需要文件: 日, 日, 月, 月, 月, 年, 年...
你得到的月份,例如:
$datetime = new DateTime("now");
$month = $datetime->format( m );
echo $month;
Copy day.php, month.php and year.php to your bundle XyTestBundleDql
Register the new functions in appconfig.yml with
doctrine:
orm:
auto_generate_proxy_classes: %kernel.debug%
entity_managers:
default:
auto_mapping: true
dql:
datetime_functions:
month: XyTestBundleDqlMonth
year: XyTestBundleDqlYear
day: XyTestBundleDqlDay