I'm saving a node programmatically. Every thing works fine except the date field which gives me an error.

My date field in cck is in Date-time format as I need to capture both and the widget type is date popup.

$node = new StdClass();

//creating a bare node
$node->created = $value['article_creation_date'];
$node->type = 'media';
//giving it type
$node->uid = $user->uid;
$node->status = 1;

//give it a published status

$node->title = $value['article_title'];
//gives title

$node->field_publish_date[LANGUAGE_NONE][]['value'] = date("d/m/Y H:i:s ", 1289799000);
$node->field_publish_date[LANGUAGE_NONE][]['timezone'] = "Asia/Kolkata";
$node->field_publish_date[LANGUAGE_NONE][]['timezone_db'] = "Asia/Kolkata";
$node->field_publish_date[LANGUAGE_NONE][]['date_type'] = "datetime";


This is the error:

Error is: `PDOException: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '15/11/2010 11:00:00 ' for column 'field_date_value' at row 1: INSERT INTO {field_data_field_date} (entity_type, entity_id, revision_id, bundle, delta, language, field_date_value) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 3 [:db_insert_placeholder_2] => 3 [:db_insert_placeholder_3] => article [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 15/11/2010 11:00:00 ) in field_sql_storage_field_storage_write() (line 514 of '

I'm open to suggestions. Thanks!

  • 1
    What's the error? – Japo Domingo Apr 3 '17 at 4:37
  • This is the error I am getting. "The website encountered an unexpected error. Please try again later." – sneha.kamble Apr 3 '17 at 5:24
  • @sneha.kamble that msg is not helpful. Please do this Show all errors while developing to get the real error Switch on strict PHP error reporting – No Sssweat Apr 3 '17 at 5:29

You are making 4 different arrays and putting part of the date config in each array.

Each time you put [] you are making a new array.

What you want is:

$node->field_publish_date[LANGUAGE_NONE][] = array(
  'value' => date("d/m/Y H:i:s ", 1289799000),
  'timezone' => "Asia/Kolkata",
  'timezone_db' => "Asia/Kolkata",
  'value' => "datetime",

for me this solved the issue:

  $node->field_publish_date[LANGUAGE_NONE][]['value'] = date("d-m-Y H:i:s ", 1289799000); I just changed the date format.

Thanks for help.

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.