Symfony 2 getter for DateTime返回字符串

时间:2016-05-17 22:22:18

标签: php symfony datetime

当我期待DateTime时,我有一个返回字符串的getter。

  

参数1传递给semesterBreakweeks ...必须是DateTime的实例,给定字符串

返回字符串2016-07-25 00:00:00。

Doctrine定义是

/**
*
* @ORM\Column(type="datetime", nullable=true)
*/
protected $term_start_date;

getter是

/**
* @return DateTime
*/
public function getTermStartDate() {
 return $this->term_start_date;
}

setter是

/**
 * @param DateTime $term_start_date
 */
public function setTermStartDate(DateTime $term_start_date) {
  $this->term_start_date = $term_start_date;
}

学期列表是通过

生成的
/**
* @return array
*/
public function findToAdd() {
  $q = $this->getEntityManager()
   ->getConnection()
   ->executeQuery("SELECT ss.*
        FROM source_semester ss
        LEFT OUTER JOIN semester s on s.term = ss.term_code
        where s.term IS NULL");

   return $q->fetchAll(\PDO::FETCH_CLASS, "Unsw\CamsSourceDataBundle\Entity\SourceSemester");
}

电话是

$startDate = $sourceSemester->getTermStartDate();
$endDate = $sourceSemester->getTermEndDate();

// The number of break weeks is the number of weeks in the semester minus the days you get.
$break_weeks = $semester->semesterBreakWeeks($startDate, $endDate);

0 个答案:

没有答案