jcroll
jcroll

Reputation: 7165

Doctrine 2: How to enter a length greater than 24 hours into a "time" field

I have a database of audiobooks. Some of those books are longer in length than 24 hours. I am having difficulty creating a doctrine entity that will map a length property longer than 24 hours because a time field accepts a DateTime object and any time over 24 hours is added onto the next day so 33 hrs becomes 9 hrs.

<?php

namespace Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Audiobook
{
    /**
     * @var \DateTime $length
     *
     * @ORM\Column(name="length", type="time")
     */
     protected $length;

Any idea how to make this work? I'm also using Symfony2.

Upvotes: 2

Views: 1253

Answers (1)

KingCrunch
KingCrunch

Reputation: 131961

It looks like you are actually looking for DateInterval instead of DateTime, because the later one represents a moment in time, which "length" can't be.

This said there is no mapping from DateInterval to a SQL-type (yet?) and even I am not aware of any interval-like SQL-type at all. what you can do is to create an own type, that maps DateInterval on a VARCHAR of the format PT28H

Upvotes: 1

Related Questions