you can't mix python formatting directly in the select........ fetch the values first and transform them later using strptime and strftime.
BTW: if startdate is a 'datetime' field you just need to strftime it later. On Monday, December 30, 2013 6:04:39 AM UTC+1, software.ted wrote: > > > I have a requirement were i need to convert a date from a query to > another format as follows: > > db(db.mytable).select(db.mytable.id, > > datetime.strptime(str(db.mytable.startDate), > '%Y-%m-%d').strftime('%d/%m/%Y')) > > The problem is am getting an error > > ValueError: time data 'mytable.startDate' does not match format '%Y-%m-%d' > > When I output the value of str(db.mytable.startDate) i get s string as > follows: > > "2013-12-04 00:00:00" > > So what i did was to change the format to include the time part as follows: > > db(db.mytable).select(db.mytable.id, > > datetime.strptime(str(db.mytable.startDate), '%Y-%m-%d > %H:%M:%S').strftime('%d/%m/%Y')) > > But still getting similar error: > > ValueError: time data 'mytable.startDate' does not match format '%Y-%m-%d > %H:%M:%S' > > > On the python console when i try to pass this command its working fine: > > >>> datetime.strptime("2013-12-04 00:00:00", '%Y-%m-%d > %H:%M:%S').strftime('%d/%m/%Y') > '04/12/2013' > > > What am I missing? > -- > > ....................................................................................... > Teddy Lubasi Nyambe > Opensource Zambia > Lusaka, ZAMBIA > > Cell: +260 97 7760473 > website: http://www.opensource.org.zm > > ~/ > Human Knowledge belongs to the world! - AntiTrust > > Man is a tool-using animal. Without tools he is nothing, with tools he is > all - Thomas Carlyle 1795-1881 > > /~ > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.