Chris, Your observation/technique I will use on one of my own projects with some modifications. I take note of Annet's problem in that he is migrating a existing DB so his dataset is already in string format. I presume that is his motivation to continue doing so.
JohnMc On Jun 22, 9:10 am, cjparsons <cjparso...@yahoo.co.uk> wrote: > It is better to store times as 'times' in the database rather than > muck about with times in string format. A lot better. > > I think this controller model / code will do what you want (note that > I didn't make a 'weekday' table and I force the current seconds to > zero to you get results that start during the current minute i.e. > 15:00 results show up at 15:00 but not at 15:01). > > CONTROLLER: > def index(): > weekday=request.now.weekday() + 1 > nowtime = request.now.time().replace(second=0,microsecond=0) > timetable=db((db.timetable.day==weekday)& > (db.timetable.time>=nowtime)).select > (db.timetable.ALL,orderby=db.timetable.time,limitby=(0,6)) > return dict(message=SQLTABLE(timetable)) > > MODEL: > (simplified from what you want) > db.define_table('timetable', > db.Field('day', 'integer'), > db.Field('time', 'time')) > > One way of disabling the time picker is to remove the line > try { $("input.time").clockpick({ starthour:0, endhour:23, > showminutes:true, military:true}); } catch(e) {}; > from web2py_ajax.html in 'views'. Another way would be do use jquery > to remove the clockpick class from the input field on document load. > But there is probably an even better way that someone else might tell > us... > > Chris > On Jun 22, 9:10 am, annet <annet.verm...@gmail.com> wrote: > > > In my model I defined: > > > db.define_table('timetable', > > db.Field(...), > > db.Field('day',db.day,default='',notnull=True), > > db.Field('time',length=5,default='',notnull=True), > > db.Field(...), > > migrate='timetable.table') > > > In a view I would like to display today's upcoming programs, the > > function reads like: > > > weekday=request.now.weekday() + 1 > > hourminute=str(request.now.hour) + ':' + str(request.now.minute) > > timetable=db((db.timetable.day==weekday)& > > (db.timetable.time>=hourminute))\ > > .select(db.timetable.ALL,orderby=db.timetable.time,limitby=(0,6)) > > > The problem is that in the database the time reads like 09:45 whereas > > hourminute reads like 9:30, consequently the query doesn't return any > > results before 10:00, after 10:00 it works alright. > > > I tried making time a field of type datetime, format it like '%H:%S' > > and then do: db.timetable.time>=request.now But a field of type > > datetime makes the calendar pop up and that doesn't allow me to enter > > times like 09:45. > > > I wonder whether request.now.hour is able to return the hours in a > > different format. Else, I guess I have to write a custom function to > > get the hours formatted correctly. > > > Kind regards, > > > Annet. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---