Is there a way to insert "0000-00-00 00:00:00" in a datetime database field?


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.

Tags: Drupal 7 / Datetime

Similar questions

hook_form_alter() and hook_nodeapi() to alter fields and insert additional data on insert
I have the code below, and I want to update the fields on my node using hook_nodeapi(). How do I set the fields on insert?
How to insert multiple tables into their respective backup tables using insert sql?
For the purpose of backup and restore i want few tables to be just backup while performing a restore process. I have created backup tables but now whenever i do restore process it shows: Actually both tables have same schema and same primary key so whenever it try to update it there is conflict. Can anyone please tell me how to do it ? One more thi...
On INSERT to a table INSERT data in connected tables
I have two tables that have a column named id_user in common. These two tables are created in my Drupal webpage at some point (that I don't know because I didn't created the Netbeans project). I checked on the internet and found that probably by adding REFERENCES 1sttable (id_user) to the second table, it should copy the value of the 1sttable (that...
Drupal 7 Date - Is there a way to change field settings if there is data in it already?
Currently I am using the date module for drupal 7 and I already have stored data in the existing date field. I want to make changes to the date field by adding "Repeating Dates", but obviously I cannot since I have data in there already. The options I came up with are: Create a completely new date field for the content type with the additional "Rep...
PHP setting of datetime field in CCK through Rules, How to stop continuous updates?
Drupal 6. Using Rules and CCK So, I have a content type that gets automatically generated with Rules. Several CCK fields get populated at creation time, including a datetime field. I want this field to get populated with the current date/time. For some reason, the Global Token fields don't work, the interface throws an error when I try to use a tok...
How to implement a mysql date or datetime field correctly in hook_schema()?
I have written a mymodule.install file which contains a schema definition to create a table in my database. This table contains two data fields. Theese fields will be populated by the users when they will fill in the specific content (example: to specific a publish date for a news). Now i didn't used the Date contributed module on purpose, cause i ...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.