Symfony2 Doctrine Qb STR_TO_DATE Unknown Function

2019-07-22 04:29发布

问题:

When i try to execute STR_TO_DATE mysql function with Doctrine query builder, symfony2 throws an exception like:

Error: Expected known function, got 'STR_TO_DATE'

My code is :

STR_TO_DATE(m.metaValue, '%m/%d/%Y') BETWEEN '".$filter["sDate"]["month"]."/01/".$filter["sDate"]["year"]."' AND '".$filter["eDate"]["month"]."/01/".$filter["eDate"]["year"]."'"

How can i get it work?

回答1:

The STR_TO_DATE function is not available in DQL. See DQL Functions.

However you can make it available by installing beberlei/DoctrineExtensions and adding this to your config.yml:

doctrine:
    orm:
        dql:
            datetime_functions:
                # ...
                strtodate: DoctrineExtensions\Query\Mysql\StrToDate