I recently created a bunch of nodes using data extracted from a large XML file. Each of these nodes has dates. In view mode, all these dates show as NOW. However, in the database the dates are correct. They are also correct when you open a node for manual editing and if you save after opening the node, they are corrected in view mode.

There was nothing unorthodox about the way these nodes were created. I created these nodes using the Nodes API in all it's sluggish glory and used node_save. All the other fields work fine.

The dates use the ISO Date field provided by the latest stable release of the Date Module. I am using Acquia Drupal 7 running on php 5.2 and mysql 5.1.60. There is no pertinent information in the log files for PHP or Apache nor on the Drupal event report.

Is this a problem with the module or is there something I can do in configuration settings to fix this? Opening up each record and saving it is not a viable solution.

Comments

mikegirard’s picture

Issue summary:View changes

Clarified language.

mikegirard’s picture

Issue summary:View changes

Added system configuration details

KarenS’s picture

Category:bug» support
Priority:Critical» Normal
Status:Active» Postponed (maintainer needs more info)

This is not a bug report, it is a support request, at least until we know whether you are even using the API correctly. And it is not critical that you don't know how to create the values you want to create programmatically. Not enough information to tell what you did, how you created things, what values you supplied, whether you understand how the API is supposed to work, or anything else.

mikegirard’s picture

No probs. You can close it out if you have no interest in investigating. Have moved on to a Python-based framework and things are going more smoothly. Good thing too, since you haven't asked any questions per getting the specifics you say you need.

Ciao.

KarenS’s picture

Status:Postponed (maintainer needs more info)» Closed (works as designed)

I have posted extensive documentation about how to debug Date problems, it's a lot of work to duplicate it over and over in every issue for people who don't read it. I manage thousands of issues in my 'free' time and there is only so much of that. I do as much as I can. I didn't say I wasn't interested in investigating. I spend thousands of hours investigating bug reports, adding new features, maintaining two different branches of the code, and working on getting date features into core for D8. You didn't provide enough information for me to do anything with this report and obviously you don't care about fixing it, so I'll close it.

mikegirard’s picture

Thanks. The date problem and now this conversation could not have been more helpfully clarifying.

xpersonas’s picture

Ah man, can this just be deleted? I'm dying to figure out how to set the date programatically. I've followed everything I see online, and then I find this dead end. I'm not trying to be negative, but this page is really unhelpful to anyone finding it through search.

xpersonas’s picture

For anyone else that ends up here, as I did...

I worked out changing the create date by putting it after node_submit.

If there's a better way, I do not know about it. As for changing the changed/update date, I'm not sure if that's possible.

<?php
if ($node = node_submit($node)) {
   
$node->created = date('U', strtotime($row['LastChanged']));
   
//$node->changed = date('U', strtotime($row['LastChanged'])); // doesn't work
   
node_save($node);
} else {
   
drupal_set_message(t("Node ".$node->title." added incorrectly"), "error");
}
?>
xpersonas’s picture

Issue summary:View changes

Added log file info.

gbirch’s picture

Issue summary:View changes

For anyone who reaches this issue hoping for help (as I just did, on an unrelated issue), it's worth knowing that the date module is very picky about how you store values; it's looking for an array structure that includes a timezone and date values in a particular format. And it's not always completely consistent in how it treats non-conforming values (as evidenced by mikegirard's problem, where the display code apparently couldn't interpret the data he had stored, but the date widget on the edit form could).

If you want to avoid the complexities, one relatively easy way to set a date field on a node programmatically is to use the entity API module and a timestamp. Please note that I have not tested this with every date type, so YMMV.

$timestamp = strtotime({your date string});  //OR $your_Date_object->getTimestamp();
$nid = {either nid of existing node or new node object}
$wrapper = entity_metadata_wrapper('node', $nid);
$wrapper->{name of date field}->set($timestamp);
$wrapper->save();

Finally, if you're experiencing mikegirard's specific problem, and don't want to re-import, consider using a simple View of the nodes with a Views Bulk Operations field to force a save on many nodes at once.