Checking for valid date input and convert appropriately
gmx at ross.cx
Fri Feb 22 01:57:03 CET 2013
On Fri, 22 Feb 2013 01:12:40 +0100, Ferrous Cranus <nikos.gr33k at gmail.com>
> Please i have been trying hours for this:
Don't do that: Spending hours on being stuck. Take a break. Call it a
Brain needs time to unstick itself.
>>> from datetime import date
>>> entry='31 03 2013'
>>> day, month, year = int(entry[:2]), int(entry[3:5]), int(entry[6:])
> datetime.strptime(date, '%d m% %Y')
> date = date.strftime('%Y-%m-%d')
> print( "<h2>date not propetly entered." )
> the user enters 21 02 2013
> a) i just need to check if its in accepted format
> b) then truncate the given date to mysql format
> That's all i want to do and i cant make it work. Plese tell me how to
> write this.
> I have tried anything i can think of.
More information about the Python-list