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

Νίκος nikos.the.gr33k at gmail.com
Wed Aug 4 19:40:45 EDT 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:

	try:
		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]) )
	else:
		#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 )

		sys.exit(0)

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