Create a node with date field (node_save) in Drupal 7
<?php
/**
* Implements hook_user_insert().
*/
function mymod_user_insert(&$edit, $account, $category) {
$rid = 2; // optionally, you can check for a specific role
if (in_array($rid, array_keys($account->roles))) {
for ($x = 1; $x <= 365; $x++) {
$datetime = date('Y-m-d', (time() + ($x * (60 * 60 * 24))));
mymod_new_node($account->uid, $datetime);
}
drupal_set_message('Created ' . $x . ' new nodes with date field for this user!');
}
}
/**
* function to create a node with date field for this user
*/
function mymod_new_node($uid, $datetime) {
$node = new StdClass();
$node->type = 'calender_item'; // machine name content type
$node->title = $datetime;
$node->language = 'nl'; .
$node->status = 1;
$node->uid = $uid;
$datetime .= " 00:00:00"; // I didn't care for the time so added this
$node->field_datum = array(
LANGUAGE_NONE => array (
0 => array(
'value' => $datetime,
'timezone' => 'Europe/Amsterdam',
'timezone_db' => 'Europe/Amsterdam',
'date_type' => 'datetime',
),
),
);
node_save($node);
}
?>