The site I'm working on right now was originally hand-coded 25 years ago, and then I rebuilt it on D5/6 almost 20 years ago. At that time, nodes didn't have an  editable authoring time or even date fields, IIRC. Since the nodes were being imported, I wanted to save the original create dates, and so used a text field to store that info.

Now that (in Backdrop) I have the option to set Authored on if needed, I would like to transition over the old nodes to use that field and remove the custom field so that users don't have to enter the date for new content of the same type.

Any suggestions on how to do this programmatically for a bunch of nodes?


Let me see if I understand. You have a bunch of nodes (D7? D6?) that contain a Field API field (or a table column?)  with the date they were created. Now you want to upgrade (?) that site into Backdrop, and use that Field API / column (?) as the created date for those existing nodes. And you also want to remove that Field API / column field.

Did I get this right?

To move the value stored in an Field API field into the created or changed node table columns, you can load all nodes, loop through them, get the value stored in the Field API/column field, convert that to a UNIX time stamp (with strtotime()), set the created property of the node, as in $node->created = $unix_time; and then save the node with $node->save();

Thanks for your help! That sounds very straightforward.

That's pretty much what I was going for, yes. It was built on D5, it turns out, then upgraded to D6 and later to D7. I have already upgraded the site to Backdrop and am now streamlining and cleaning up stuff so new content can be added more easily.

Is created where the node field data is stored for the "Authored on" timestamp in the node edit form?

Is created where the node field data is stored for the "Authored on" timestamp in the node edit form?

Yes, the "authored on" date is saved in the created column. The "changed" column stores the date when the node was last edited.