Datetime string reformatting

I

Igor Korot

Hi, ALL,
I am trying to comprehend what is required to get a successful processing. ;-)
My script receives a data from the csv file. In this csv file there is
a datetime field.
This datetime field is formatted as follows: %m/%d/%Y
%H:%M:%S.{milliseconds}. I'm reading this field into the string with
this format.

The trouble comes from the fact that I need to insert this value into
mySQL. Doing it directly gives me an error: "Incorrect formatting".
After a bit of googling and trial I found out that mySQL is looking
for the format of '%Y/%m/%d %H:%M:%S.{milliseconds}.

There is a mySQL function which transfers the data into the proper
format: STR_TO_DATE(), but I can't obviously call it since it is not
known to Python.

Now obviously there should be a possibility to reformat this string.
I guess I can try to do:

mydate = date(mydate_from_csv)
text = mydate.format()

but this feels like an ugly hack.

Is there a better alternative?

Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top