On Sun, 25 Mar 2012 16:41:09 -0700 (PDT), niph...@gmail.com said:
Doh, you're right. All the datetime api on fields are extracting, not
converting the actual value
Yes, and I've also found that, with Sqlite at least, web2py doesn't
carry out datetime arithmetic correctly within the DAL
Not sure if this is relevant, but you can do the following with datetime.
import datetime
a = datetime.datetime(2007, 12, 6, 16, 29, 43, 79043)
b = datetime.datetime(2011, 10, 3, 12, 0, 0, 0)
c = b-a
c
datetime.timedelta(1396, 70216, 920957)
(c.microseconds + (c.seconds + c.days * 3600 *
problem is doing it within the db ^_^
Actually your answer is correct, and I need to rectify my example
period_to_update = db(db.periods.id==1).select().first()
start_time = period_to_update.start_time
elapsed = request.now - start_time
period_to_update.update_record(end_time=request.now,
On Mon, 19 Mar 2012 14:45:51 -0700 (PDT), niph...@gmail.com said:
for every period, duration is calculated as:
duration = db.periods.end_time.seconds() -
db.periods.start_time.seconds()
This is wrong.
I reworked my data model so that the period start and stop fields were of
type datetime. I
Doh, you're right. All the datetime api on fields are extracting, not
converting the actual value
At this point you can sum up years difference, month difference, etc etc
etc separately and then extract the time passed by.
.
duration_ye = (db.periods.end_time.year() -
On Mon, 19 Mar 2012 14:45:51 -0700 (PDT), niph...@gmail.com said:
for every period, duration is calculated as:
duration = db.periods.end_time.seconds() -
db.periods.start_time.seconds()
now, get a list of all durations...
result = db(db.periods.id0).select(db.periods.id, duration)
This
Perhaps you could add the seconds as a virtual lazy field.
On Wednesday, March 21, 2012 11:25:41 PM UTC-7, backseat wrote:
On Mon, 19 Mar 2012 14:45:51 -0700 (PDT), niph...@gmail.com said:
for every period, duration is calculated as:
duration = db.periods.end_time.seconds() -
We shall come to an agreement when you explain plainly what is your real
model...
it seems that your start and end columns are time and not datetime...
Time fields don't have a seconds() method, only datetime!
Perhaps you could add the seconds as a virtual lazy field.
That sounds worth investigating, thanks.
We shall come to an agreement when you explain plainly what is your real
model... it seems that your start and end columns are time and not
datetime... Time fields don't have a seconds()
In my original posting, I said: the periods table has id, date,
start_time, end_time (and other fields). I suppose I assumed that the
presence of a 'date' field implied that the *_time fields were indeed of
type time, but I'm sorry if that wasn't clear.
my point was: my model implied datetime,
I'm having problems getting a valid value for seconds() from a time field
under Sqlite. I can extract a time:
for row in db(db.t_periods.id==40).select(db.t_periods.f_period_end):
... print row
...
Row {'f_period_end': datetime.time(17, 50, 51)}
However, if I try to get the seconds(), it
Wait seconds() is a method of a datetime field
when you call the sum, the method is called, but if you are going to
fetch it directly, you must use:
rows = db(db.t_periods.id==40).select(db.t_periods.f_period_end)
for row in rows:
print row.f_period_end.seconds()
On Wed, 21 Mar 2012 14:43:42 -0700 (PDT), niph...@gmail.com said:
rows = db(db.t_periods.id==40).select(db.t_periods.f_period_end)
for row in rows:
print row.f_period_end.seconds()
No, that gives an error:
rows = db(db.t_periods.id==40).select(db.t_periods.f_period_end)
for row in
Thanks Niphlod, that looks good and I will try it soon.
--
You can have everything in life you want if you help enough other people
get what they want - Zig Ziglar.
Who did you help today?
I've hit an error (web2py bug?) in Niphlod's well-explained example.
I *was* running web2py.1.99.4, which gave this:
duration=(db.t_periods.f_period_end.seconds() -
db.t_periods.f_period_start.seconds()).sum()
what db engine are you using ?
Il giorno martedì 20 marzo 2012 21:55:58 UTC+1, backseat ha scritto:
I've hit an error (web2py bug?) in Niphlod's well-explained example.
I *was* running web2py.1.99.4, which gave this:
duration=(db.t_periods.f_period_end.seconds() -
PS: by the way, your query is not what I suggested :P
assuming the example I posted, you are trying to do
durations =
db(db.periods0).select(db.periods.id,duration,groupby=db.periods.task_id)
error here is db(db.periods0) and not db(db.periods*.id*0)
corrected this error, you have another
I'm using sqlite, and I'm embarrassed about my errors. Thanks for your
help.
--
You can have everything in life you want if you help enough other people
get what they want - Zig Ziglar.
Who did you help today?
Another DAL challenge. accepted!
assuming the model:
db.define_table('tasks',
Field('name')
)
db.define_table('periods',
Field('task_id', db.tasks),
Field('start_time', 'datetime'),
Field('end_time', 'datetime'),
)
You'd like to calculate the
19 matches
Mail list logo