How to format a datetime MySQL database field to local using strftime()
Please provide more information and show how you've debugged the code so
On 25/02/19 7:03 AM, vergos.nikolas at gmail.com wrote:
> pymydb.execute( '''SELECT host, ref, location, useros, browser, visits, hits, downloads, authuser FROM guests
> WHERE pagesID = (SELECT ID FROM pages WHERE url = %s) ORDER BY visits DESC''', page )
> data = pymydb.fetchall()
> for visit in visits:
> visit = visit.strftime('%A %e %b, %I:%M %p')
Is this the actual code? How do we get from the collection of
tuples/dicts called "data", to an iterable called "visits"?
Also: %e should likely be %w or %d.
Which 'connector' are you using between MySQL and Python?
(may not be the same as the one I favor)
> 'visit' is being returned from database containing a MySQL datatime field that i want to change to another format which is ('%A %e %b, %I:%M %p') thats why i'm using that function. If not convert or comment out then results are not appearing normally.
Where are these actual results? (might they help us to help you?)
What do you see, as the same row/col, when using the MySQL cmdLN shell
or MySQL-Workbench (etc)?
Have you shown us what comes back as the first row's value for "visit"?
Please check its type() before the code processes it further - is it
coming back as a Python date or time format, or is it a string?
Remember logging or even debug print()-s are your friend!