Checking for valid date input and convert appropriately
Mark Lawrence
breamoreboy at yahoo.co.uk
Thu Feb 21 18:30:53 EST 2013
On 21/02/2013 23:18, Ferrous Cranus wrote:
> Then i try to save the date as MySQL wants but it just aint happening:
>
> date = datetime.strftime(date, '%Y-%m-%d')
>
> Can you help me please save the user entered date to MySQL format?
>
I suggest testing your code at the interactive prompt, so something like.
c:\Users\Mark>python
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32
bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> date = '21 02 2013'
>>> date = datetime.strftime(date, '%Y-%m-%d')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: descriptor 'strftime' requires a 'datetime.date' object but
received a 'str'
--
Cheers.
Mark Lawrence
More information about the Python-list
mailing list