I have a custom module, using the Form API, that I am trying to insert a user selected date and time into the database. But, the values are always 0000-00-00 00:00:00 in the database. The database field type is "datetime" that I am trying to insert into. Can anyone help me with the php syntax that I should use. I can get the other values from my form into the database with the same query, just not the proper datetime value. Am I using the correct database field type? Do I need to format the form value a special way. I am fairly new to drupal module development and have never tried to insert a date before. Any help would be greatly appreciated.

Comments

jaypan’s picture

Drupal stores dates as unix timestamps, so you need to use type int in the database for times, or else you need to alter your queries to convert your dates to the mysql date format.

Contact me to contract me for D7 -> D10/11 migrations.