PHP code example of salamek / doctrine-daterange
1. Go to this page and download the library: Download salamek/doctrine-daterange library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
salamek / doctrine-daterange example snippets
use Doctrine\DBAL\Types\Type;
use Salamek\Doctrine\DBAL\Types\DateRangeType;
Type::addType(
DateRangeType::DATERANGE,
'Salamek\\Doctrine\\DBAL\\Types\\DateRangeType'
);
/**
* @Entity()
* @Table(name="jobs")
*/
class Job
{
/**
* @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
* @Id()
*/
private $id;
/**
* @Column(type="daterange")
*/
private $range;
/**
* @return \Salamek\DateRange
*/
public function getRange()
{
return $this->range;
}
/**
* @param \Salamek\DateRange $range
*/
public function setRange(\Salamek\DateRange $range)
{
$this->range = $range;
}
}
$annualJob = new Job();
$annualJob->setRange(new \Salamek\DateRange(new \DateTime, (new \DateTime)->modify('+1 year')));
$entityManager->persist($annualJob);
$entityManager->flush();
$entityManager->clear();
$jobs = $entityManager->createQuery(
"SELECT j FROM Jobs j"
)->getResult();
echo $jobs[0]->getRange()->getStartDate()->format(DateTime::ISO8601); // "NOW"
echo $jobs[0]->getRange()->getEndDate()->format(DateTime::ISO8601); // "NOW +1 year"