Hi,

I want a way to set a node's creation time to the current date, every day, using the cron.php script, just like this :
the node X was created on 10/10/10, I want to change it's creation date every day when cron.php is executed.

are there a way to do this ?

Regards

Comments

Drave Robber’s picture

function yourmodule_cron() {
  $yournid = 513; // Or whatever is the NID of the poor node.
  if (date('G') == 9) { // It's 9 a.m. server time, for example.
    $yournode = node_load($yournid);
    $yournode->created = time() - 300; // Let us pretend it was created five minutes ago.
    node_save($yournode);
  }
}
LeMale’s picture

worked well, thanks!

To do so, I created a custom module where I placed this function, is there a faster way ?

Drave Robber’s picture

Sort of. Could use SQL Cron and poke db directly like

UPDATE node SET created = UNIX_TIMESTAMP() - 300 WHERE nid = 513 AND created - UNIX_TIMESTAMP() > 86400

If you need complex conditions, it's harder to stuff them into a single line of SQL; above would be executed not after 9 a.m. but when at least 24 hours (86400 seconds) have passed since node creation time.

If the node creation time on your site is displayed as date only so that changing it every hour wouldn't seem suspicious, you might omit all conditions and 'minus 300 seconds' part as well.