So I'm making quite a few nodes through a script, an action. To do this I'm using the form_state drupal_execute method.

However because there is a lot of processing per node in one batch I get lots of nodes with different time stamps.

Is there any way to manually edit the timestamps a part from going into the DB? I've tried this: outside loop: $time = time();

inside loop:

form_state['values'] = $time;

And give the same timestamp to all the nodes. But apparently druapl_execute gives them a new time stamp.


EDIT: Solved! I ended up adding this line, it was the fastest solution I could think of.

db_query("UPDATE {node} SET created = %d WHERE nid = %d", $time, $form_state['nid']);

  • @DK if you solved you problem, please post your solution as an answer and mark it accepted to help other people find the solution more easily in the future – Laxman13 Oct 5 '11 at 13:08

Another solution is assigning the created property of the $node object before calling $node->save.


$body_text = 'This is the body text I want entered with the node.';
$created_time = time();

$node = new stdClass();
$node->type = 'article';

$node->title    = 'Node Created Programmatically on ' . date('c');
$node->language = LANGUAGE_NONE;

$node->body[$node->language][0]['value']   = $body_text;
$node->body[$node->language][0]['summary'] = text_summary($body_text);
$node->body[$node->language][0]['format']  = 'filtered_html';

$path = 'content/programmatically_created_node_' . date('YmdHis');
$node->path = array('alias' => $path);

$node->created = $created_time;


For more information please see the API docs on node_save().

The solution above has the added bonus of not requiring additional databases queries to clean up the timestamps after the node was created.

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.