Struggling to convert a mysql datetime object to a python string of a different format
nikos.the.gr33k at gmail.com
Thu Aug 5 18:31:18 CEST 2010
On 5 Αύγ, 11:55, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> On Wed, 4 Aug 2010 16:40:45 -0700 (PDT), Íßêïò
> <nikos.the.gr... at gmail.com> declaimed the following in
> > for entry in row:
> > entry = datetime.datetime.strftime( entry, '%d %b, %H:%M' ) #!!!
> > this is wrong!
> > print ( ''' <td> %s </td> ''' % entry )
> > Apart from that i don't know how iam supposed to print it, because the
> > date string is the 3rd string in every row of the dataset.
> As you state, it is the third item in each returned row... So why
> are you trying to treat EVERY item in the row as a date?
Because when i try to prin the 3 items liek that
print row, row, row
it gives me an error, so i dont knwo how to tell it how to print the
3rd item differently.
> Since MySQLdb appears to return datetime objects (my quick test is
> showing datetime.date for dates in a test database) you should be
> probably be using
> formatted_entry = entry.strftime("%d... %M")
I tried that myself yesterday but look it fails to the following
64 for entry in row:
65 formatted_entry =
entry.strftime('%d %b, %H:%M')
66 print ( ''' <td> %s </td> ''' %
formatted_entry undefined, entry = '178-124-186.dynamic.cyta.gr',
AttributeError: 'str' object has no attribute 'strftime'
args = ("'str' object has no attribute 'strftime'",)
More information about the Python-list