Chris

> It is better to store times as 'times' in the database rather than
> muck about with times in string format. A lot better.

Hence my remark: 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.


I changed my code a you suggested in both your posts:


In my model:

def timeplain(field,value):
    if value == None:
        value = ''
    id = '%s_%s' % (field._tablename, field.name)
    return INPUT
(_type='text',_id=id,_class='time_plain',_name=field.name,value=str
(value),requires=field.requires)


... and:

db.define_table('timetable',
    db.Field(...),
    db.Field('day',db.day,default='',notnull=True),
    db.Field
('time',type='time',default='',notnull=True,widget=timeplain),
    db.Field(...),
    migrate='timetable.table')


In my controller:

...
nowtime=request.now.time().replace(second=0,microsecond=0)
timetable=db((db.timetable.day==weekday)&
(db.timetable.time>=hourminute))


I have two more questions though:

In the interface the time displays like 15:00:00 how do I get it do
display in the format: 15:00?


How do I validate the field to have the correct format?


John,

> 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.

My motivation to proceed as I did was that I couldn't get this:

> 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.

... to work. Hence, my "mucking about with times in string format" ;-)


Thank you both for your help,

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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to