在表列(a.paymentDate)
中插入日期格式爲Y-m-d H:m:i
格式。我想查詢特定日期的所有條目。爲此,我必須將日期格式從Y-m-d H:m:i
更改爲Y-m-d
。我的查詢是在下面給出的。在symfony2中更改原則查詢中的日期格式
namespace Regal\SmsBundle\Repository;
use Doctrine\ORM\EntityRepository;
/**
* DailyTransactionRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class DailyTransactionRepository extends EntityRepository
{
public function getDailyPayment($studentId,$paymentDate)
{
$paymentDate= new \DateTime('2013-03-11');
$query = $this->getEntityManager()->createQuery("
SELECT a.id, a.amont, a.paymentDescrip, a.paymentType, a.paymentDate
FROM RegalSmsBundle:DailyTransaction a
WHERE DATE(a.paymentDate) = :paymentDate AND a.students = :studentId
")
->setParameter('studentId', $studentId)
->setParameter('paymentDate', $paymentDate->format('Y-m-d'))
;
return $query->getResult();
}
}
您正處於正確的軌道上,但由於Doctrine DQL查詢處理器無法識別DATE,因此無法使用。 – Cerad 2013-03-19 16:26:22
嗨艾哈邁德 - 它顯示以下錯誤'錯誤:預期的已知功能,得到'日期'' – Tushar 2013-03-19 16:36:14
@Cerad你是對的。 [似乎沒有被支持](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#dql-functions)。 @ Tushar,看看Cerad的延伸。 – 2013-03-19 16:41:29