sfDoctrineRecord::getDateTimeObject PHP Method

getDateTimeObject() public method

Get the Doctrine date value as a PHP DateTime object, null if the value is not set
public getDateTimeObject ( string $dateFieldName ) : DateTime | null
$dateFieldName string The field name to get the DateTime object for
return DateTime | null $dateTime The instance of PHPs DateTime
    public function getDateTimeObject($dateFieldName)
    {
        $type = $this->getTable()->getTypeOf($dateFieldName);
        if ($type == 'date' || $type == 'timestamp' || $type == 'datetime') {
            $datetime = $this->get($dateFieldName);
            if ($datetime) {
                return new DateTime($datetime);
            }
        } else {
            throw new sfException('Cannot call getDateTimeObject() on a field that is not of type date or timestamp.');
        }
    }