How to set the creation date

This page describes how to set the creation date and effective date to a given value.

Im ZMI add a Script (Python) to your Plone's root, name it setdate and fill it with the following code:

 # set creationDate and effectiveDate to a given date.
 # by jensens

 date="-".join(traverse_subpath)

 try:
     d= DateTime(date)
 except:
     return "problem with subpath '%s'. usage: setdate/YYYY/MM/DD" % date

 context.setModificationDate(date)
 context.setCreationDate(date)
 context.setEffectiveDate(date)
 context.reindexObject()

 return "date on '%s' successfully set to %s." % (context.title_or_id(), date)

Navigate to the object you want to change and append to its URL setdate/2005/09/17.

Example:

 http://www.linux.org/Members/torvalds/news_linuxstarted/setdate/1991/08/25

It works not for Plone 2.1.1 (for some reason there is setModificationDate and setCreationDate not available in restricted code. This will be fixed in upcoming Archetypes releases (just replace ExtensibleMetadata.py by the one from Archetypes SVN release-1_3-branch). Here both methods are protected by Manage Portal.

Thats it.

Modification date

Posted by Pupeno at Jul 30, 2006 08:51 PM
To be able to succesfuly save a different modification date I had to change the order of the date setting calls to:

context.setCreationDate(date)
context.setEffectiveDate(date)
context.reindexObject()
context.setModificationDate(date)

(On Plone 2.5 if it matters).

Steps for Plone 3

Posted by Sean Fulmer at May 26, 2008 01:07 AM
item.setCreationDate(date)
item.setEffectiveDate(date)
item.setModificationDate(date)
item.indexObject() # NOT redindexObject()

Add times to URL

Posted by Brent Woodruff at Jul 21, 2008 04:22 AM
I needed to set times too, so here's a quick hack for specifying that in the URL along with the date:

# set creationDate and effectiveDate to a given date.
# by jensens
# modified to include times and link back 2008-07-20
# by Brent Woodruff

date="-".join(traverse_subpath)
date=date[:10] + ' ' + date[11:13] + ':' + date[14:16]

try:
    d= DateTime(date)
except:
    return "problem with subpath '%s'. usage: setDate/YYYY/MM/DD/HH/MM" % date

item.setCreationDate(date)
item.setEffectiveDate(date)
item.setModificationDate(date)
item.indexObject() # NOT redindexObject()

return '<html><head></head><body>The date on <a href="%s">%s</a> has been successfully set to %s.</body></html>' % (context.absolute_url(), context.title_or_id(), date)

Whoops

Posted by Brent Woodruff at Jul 21, 2008 04:26 AM
There is an error in the above, mixing the code from the article (using context) with the comments (using item). This is fixed. I'm also including a quick link back to the item in the output...

# set creationDate and effectiveDate to a given date.
# by jensens
# modified to include times and link back 2008-07-20
# by Brent Woodruff

date="-".join(traverse_subpath)
date=date[:10] + ' ' + date[11:13] + ':' + date[14:16]

try:
    d= DateTime(date)
except:
    return "problem with subpath '%s'. usage: setDate/YYYY/MM/DD/HH/MM" % date

context.setCreationDate(date)
context.setEffectiveDate(date)
context.setModificationDate(date)
context.indexObject() # NOT redindexObject()

return '<html><head></head><body>The date on <a href="%s">%s</a> has been successfully set to %s.</body></html>' % (context.absolute_url(), context.title_or_id(), date)

Whoops

Posted by Coupland at Jan 13, 2009 09:16 PM
This is exactly what I have been searching for! However, strangely, I've noticed that setting the dates: 04/01/2004, 11/01/2007 and 04/01/2008, the time comes in off an hour. I can't figure out why this is and all other dates that I've tried work.

For example: If I use the URL: http://pc87/newsletters/internal/Backsite-04-04.pdf/setdate/2004/04/01/00/00

Then the file would have a modification date of 03/31/2004 01:00 AM.

Crazy, huh? Any help would be greatly appreciated!