Struggling to convert a mysql datetime object to a python string of a different format

Νίκος nikos.the.gr33k at
Thu Aug 5 01:40:45 CEST 2010

Okey, i have many hours now struggling to convert a mysql datetime
field that i retreive to a string of this format '%d %b, %H:%M'

I google a lot but couldnt found out how to format it being a string

Here si the code so far:

		cursor.execute( ''' SELECT host, hits, date FROM visitors WHERE page
= '%s' ORDER BY date DESC ''' % (page) )
	except MySQLdb.Error:
		print( "Error %d: %s" % (e.args[0], e.args[1]) )
		#display results
		print ( '''<center><br><h3> ( Επισκέπτης ) ----- ( Επισκέψεις )
----- ( Ημερομηνία ) </h3><br>''' )
		print ( '''<table border = "5" cellpadding = "5">''' )

		results = cursor.fetchall()

		for row in results:
			print ( ''' <tr> ''' )

			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.

Please help me out!

More information about the Python-list mailing list