Skip to content
Advertisement

TYPO3 date issue

I’m a new user of TYPO3 and I’m creating a simple extension for registering data in backend and for display them.

I have two date fields with which we can choose dates ourselves to determine the duration of an event by example startDate and endDate

However, when I display the elements saved thanks to my extension, it does not display the date on the date entered, but on today’s date.

In database, the date is recorded in UNIX format but with the right values, for example I entered this date: 21-01-2022 and it records 1642806000 in database

I don’t know why I have this problem, you think it is a configuration problem?

Here is some snippet of code:

TCA

 'start_date' => [
            'label' => 'start date',
            'config' => [
                'type' => 'input',
                'renderType' => 'inputDateTime',
                'eval' => 'date, int',
                ],
        ],
        'end_date' => [
            'label' => 'end date',
            'config' => [
                'type' => 'input',
                'renderType' => 'inputDateTime',
                'eval' => 'date, int',
            ],
        ],

SQL

start_date int(11) DEFAULT '0' NOT NULL,
end_date int(11) DEFAULT '0' NOT NULL,

Model

protected $startdate = '';

protected $enddate = '';

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

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


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

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

HTML

<f:format.date format="d.m.Y">{event.start_date}</f:format.date>

Thanks you for your help

i’m using TYPO3 10.4

Advertisement

Answer

You need to use underscores in SQL, therefor the mapping is not working. Extbase expects a SQL field named start_date when you use startDate in your model.

It’s quite hidden in the Extbase Docs, but I found it (and will change it to be more prominent): https://docs.typo3.org/m/typo3/book-extbasefluid/main/en-us/6-Persistence/1-prepare-the-database.html#preparing-the-tables-of-the-domain-objects

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement