Hi Everyone!  I have another 'new guy' question, for those who have been 
following me so far.

I need to be able to look at two dates and determine if they match while 
ignoring the time. Specifically, a date vs today
Lets say I have a model of appointments and in that model there is some 
appointment date field, so in appointments table we have:

Field('appointment_date', 'datetime'),

and I want to grab today's appointments in a controller:

appointments = db(db.appointments.appointment_date == 
request.now.date()).select(),

The will be empty because none of the times will match.  (Or maybe 1 will 
if I am extremely lucky to hit the db at that moment the time matches but 
anyways..)

So far I've found 2 solutions and both have problems:

Solution 1.  Format my Field so that it doesn't have 
hours/minutes/seconds.  Something like format=('%Y%m%d'), (I may have typed 
that wrong).  Now this works: 

db.appointments.appointment_date == request.now.date()

The Problem:  The SQLFORMs have this little calendar popup when entering 
the date in, and this forces you to have the time stamp.  This means any 
SQLFORMs I have that let the user enter a date will always be broken if you 
try to use the calendar.  

Solution 2:  query using | (or) like so:

query1 = db.appointments.appointment_date.year() == request.now.year
query2 = db.appointments.appointment_date.month() == request.now.month
query3 = db.appointments.appointment_date.day() == request.now.day

appointments = db(query1 | query2 | query3).select()

This works! It's actually what I went with, and everything was going 
swimmingly!  I didn't have to fiddle with ajax or whatever controls the 
calendar in the SQLFORMs, although I realize I should get around to 
learning how to do that at some point. So what's the problem?

The Problem:  Google app engine does not allow this:(  Found this out the 
hard way.  

So, are there easier ways to check if a datetime field is equal to today?

Thanks for all the help so far.



-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to