0

I need to add 60 Years to the date of birth of a person/worker, this person is stored in the database and I have the following code to define this person plus the getters and setters:

/**
 * @ORM\Entity
 * @ORM\Table(name="Worker")
 * @ORM\Entity(repositoryClass="Osd\RetireBundle\Entity\WorkerRepository")
 */
class Worker
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $idWorker;

/**
 * @ORM\Column(type="string", length=20)
 */
private $omang;

/**
 * @ORM\Column(type="string", length=100)
 */
private $workerTitle;


/**
 * @ORM\Column(type="string", length=100)
 */
private $workerName;

/**
 * @ORM\Column(type="string", length=100)
 */
private $workerSurname;

/**
 * @ORM\Column(type="date")
 */
private $birthDay;

/**
 * @ORM\Column(type="date")
 */
private $dateOfEmployment;

Inside this person/Worker, I do not really know is is correct to do it there, but I was trying to create a method like this:

    public function getRetireDate (){
   if($this->getBirthDay()) 
       return $retireYear = $this->getBirthDay()->add(new DateInterval('P60Y'));
}

I dont really know where to add the method?, but for now is inside the worker (Im new to symfony). but when ever I call it it gives me this error:

FatalErrorException: Error: Class 'Osd\RetireBundle\Entity\DateInterval' not found in /var/www/Org/src/Osd/RetireBundle/Entity/Worker.php line 202

Any one who has done or knows how and where to achieve this feature? Regards and thank you in advance.

Abel
  • 538
  • 5
  • 8
  • 28

2 Answers2

1

I think I have sorted out the problem and your answer @david was really helpful; now my method looks like this:

public function getRetireYear (){
       return $this->retireYear = $this->getBirthDay()->add(new \DateInterval('P60Y'));
}

and I have a private var inside the Worker called $retireYear. that's it. It works wonderfully. Thank you.

vascowhite
  • 18,120
  • 9
  • 61
  • 77
Abel
  • 538
  • 5
  • 8
  • 28
  • Thank you @vascowhite I'm really happy about the solution. – Abel Oct 03 '13 at 08:57
  • You can accept this answer, so that other uses know that you have found a solution. – vascowhite Oct 03 '13 at 10:06
  • Be careful and verify that the birth date itself is not getting 60 years added. The add method is a bit unusual. You probably want to clone the birth date then add. – Cerad Oct 03 '13 at 12:01
-1

The getRetireDate() function is in Worker entity. The error that occur is probably you don't have DateInterval entity or you forget to include DateInterval entity to your Worker entity.

david
  • 3,225
  • 9
  • 30
  • 43
  • DateInterval is not an Entity in my Sumfony project. DateIntevel is and internal PHP Class I took it from [here](http://php.net/manual/en/datetime.add.php). and I do not really know how does it work, is my first time using it. I'll keep researching any way. thank you. I'll post any progress. – Abel Oct 03 '13 at 08:15