i'm triying to create an custom entity, to store data i'm creating a schema through BaseFieldDefinition (or some near). The problem is that some fiels of type datetime are created in the database with type Varchar(20). The field definition is below:

        $fields['created_at'] = BaseFieldDefinition::create('datetime')
        ->setLabel(t('Fecha de creación'))
        ->setDescription(t('Fecha de creación de la empresa en el sistema'))
            'datetime_type' => 'datetime'

I'm triying set the default value with and without ", thanks in advance.

  • I want say that values given on setLabel and setDescription are ignored too. – Jjsg08 Mar 5 at 21:31
  • Side note: Always only pass English strings to the t-function. – leymannx Mar 5 at 22:24
  • Welcome to Drupal Answers! Do you need this as a date string, eg '2019-03-05T17:39:00' or as a numerical, unix timestamp, eg 1551825618? Or does it not matter? – mpdonadio Mar 5 at 22:40
  • Date string pls, how the datetime type of mysql native – Jjsg08 Mar 5 at 23:05
  • I'll try to answer properly when my kid gives back my real computer :) but datetime fields are always varchar in the database since the native database types aren't portable. The ->setDefaultValue() should work if you use an ISO8601 string like in my comment above. – mpdonadio Mar 5 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.