Hello,

I got my last issue resolved, working great thanks to you guys. I have a wide variety of date formats that I need to parse into this format: MM/DD/YYYY HH:MM:SS (a mysql DATETIME type value)..

I have tried:

post_date = time.strftime("%Y-%m%d %H:%M:%S", i.issued)

However, this gives me:

Traceback (most recent call last):
  File "./parse.py", line 34, in ?
    print time.strftime("%Y-%m-%d %H:%M:%S", i.issued)
TypeError: argument must be sequence of length 9, not 20

i.issued is a variable, with this as an (example) value:
(2005, 7, 24, 15, 32, 0, 6, 205, 0). I believe this is called a tuple?

If anybody knows how I can successfully parse this type of value into the MM/DD/YYYY HH:MM:SS format, I would be extremely grateful. Thank you! :)

This works fine ...

import time

timeTuple = (2005, 7, 24, 15, 32, 0, 6, 205, 0)
print "MM/DD/YYYY HH:MM:SS =",time.strftime("%m/%d/%y %H:%M:%S", timeTuple)

There must be something wrong with i.issued, you can force it to be a tuple with tuple(i.issued).

You can create this timeTuple with ...

timeTuple = time.strptime("07/24/05 15:32:00", "%m/%d/%y %H:%M:%S")
print timeTuple   # shows (2005, 7, 24, 15, 32, 0, 6, 205, -1)

The -1 is just the daylight savings time flag.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.