Get the creation time of a member on Plone

There could be many reasons why you want to check the creation time of a site member on Plone. Use this snippet (change the members[0] as necessary):

from Products.CMFCore.utils import getToolByName

pmt = getToolByName(context, 'portal_membership')
members = pmt.listMembers()
print members[0]._p_mtime                   # => 1360156585.44

As far as I’ve observed, members are returned in alphabetical order by .listMembers().

This returns the time as a Unix timestamp, so to make this into something more manipulable and/or readable you can do this:

import datetime

mtime = datetime.fromtimestamp(members[0]._p_mtime)
print mtime.strftime('%Y-%m-%d %H:%M:%S')   # => 2013-02-06 14:16:25

All this was tested on Plone 4.0.2.

For more information about Plone:

Tags: