2

Is there a way to insert "0000-00-00 00:00:00" datetime database field?
Should I change the database field's default value to "0000-00-00 00:00:00"?

I got replies on Stack Overflow, and it works with plain PHP, but it gives an error with Drupal.

  • Hello and welcome. Please tell us how you defined database column you want to insert data to, what PHP code you are trying to execute (and how you injected it to Drupal), and what error do you see. – Mołot Jul 6 '13 at 9:10
1

In Drupal 7 DB API, support for the datetime type was removed. This means that you must use use mysql_type or pgsql_type if you want this functionality. Below is an example of of to declare this schema provided your database is MySQL. By setting not null to FALSE, you can store an empty value (''), which is equivelent to '0000-00-00 00:00:00':

'mydate_date' => array(
  'description' => t('My date field.'),
  'type' => 'varchar',
  'mysql_type' => 'datetime',
  'not null' => FALSE,
),

Note that to make the schema portable, you should provide a fallback type (varchar) for the case that the database is not mySQL.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.