question about time stamp in template

32 views
Skip to first unread message

wolfv

unread,
May 26, 2010, 4:36:06 AM5/26/10
to we...@googlegroups.com
I have some record in sqlite ,every record have a time stamp;
I select them 
====
resu   = init.db.select('messages')
====
and use this code to print them in the template file
======
$for row in resu:
      <li>$row.name@$row.time Says:$row.cont</li>
======
but now I dont know how to print the time formated.
Need your help ! THX.

Justin Davis

unread,
May 26, 2010, 11:26:37 PM5/26/10
to web.py
This depends on your schema. If the datetype in your schema is a date
or datetime, the output from the db.select statement should be a
python datetime object. See this page:

http://docs.python.org/library/datetime.html

Specifically the strftime method. Your template will probably involve
something like:

<li>$row.name@$row.time.strftime("%b %d, %Y")</li>

ShiaoMing Young

unread,
May 26, 2010, 11:27:32 PM5/26/10
to we...@googlegroups.com
if your $row.time is a datetime

eg:
$row.time = datetime.datetime.now()

then you can use the function strftime to format your time

Blog: http://shiao.org
Twitter: @lepture

> --
> You received this message because you are subscribed to the Google Groups "web.py" group.
> To post to this group, send email to we...@googlegroups.com.
> To unsubscribe from this group, send email to webpy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webpy?hl=en.

wolfv

unread,
May 27, 2010, 3:28:59 AM5/27/10
to we...@googlegroups.com
Sorry in my database time's type is INT.

I thougt I find the solution 
====
import time
globals = {'time': time} 
render = web.template.render('templates', globals=globals)
====

and then in the template file  I have the time's series mothod :)
Reply all
Reply to author
Forward
0 new messages