StifanI use that method to build dates quite often. However, I don't know how to translate that into a DAL query.-Jim
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/-mKujQj0oB4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I don't think that will do it. The date stored in the database would be 10/15/1980, or 10/21/1993.Those should both show a birthday in the month of August.
But, I don't want just a matching month. I want it for the next 30 days.So, on December 15th I should see all birthdays between December 15th and January 15th regardless of what year the birthday is in.Jim
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
On Tuesday, October 3, 2017 at 4:48:52 PM UTC-7, Jim S wrote:I don't think that will do it. The date stored in the database would be 10/15/1980, or 10/21/1993.Those should both show a birthday in the month of August.
Er, October?
But, I don't want just a matching month. I want it for the next 30 days.So, on December 15th I should see all birthdays between December 15th and January 15th regardless of what year the birthday is in.Jim
It's not too much more. You identify the current day and month, and the day and month of 30 days from now, and do 2 selects:
First for the bdays whose month matches the current and whose day is greater than today.
Second for the bdays whose month matches the successor month and whose day is less than the +30 day.
def overview():
results = db((db.composer.birthdate.month()==request.now.month)&(db.composer.birthdate.day()>=request.now.day)).select( db.composer.given_names, db.composer.surname, db.composer.birthdate,
limitby=(0, 75), orderby=~db.composer.birthdate.month()|db.composer.birthdate.day())
if len(results) < 3:
results2 = db(db.composer.birthdate.month()==monthsuccessor(request.now.month)).select( db.composer.given_names, db.composer.surname, db.composer.birthdate,limitby=(0,2), orderby=db.composer.birthdate.day())
results = results | results2
return dict(records=results)
def monthsuccessor(month): if month == 12: return 1 return month + 1
(My example covers years from 1600 to present, for composers. i also have getting everybody in any single calendar month, which is just one query. Results for October:
--
# find the upcoming birthdays
start_date = request.now.date()
end_date = start_date + relativedelta(months=+1)
this_month = db((db.employee.dob.month() == start_date.month) &
(db.employee.dob.day() >= start_date.day)).select(db.employee.employeeId)
next_month = db((db.employee.dob.month() == end_date.month) &
(db.employee.dob.day() <= end_date.day)).select(db.employee.employeeId)
upcoming_birthdays = len(this_month | next_month)
-Jim