Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85752
| From | Rob Gaddi <rgaddi@technologyhighland.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Python & Peewee Query Example Needed |
| Date | 2015-02-17 20:52 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <mc09ma$3mq$1@dont-email.me> (permalink) |
| References | <784409a1-84f6-42d1-b35e-c1f6306060d6@googlegroups.com> <2135a3d0-02c0-47c0-9827-ccddbfb768f6@googlegroups.com> |
On Mon, 16 Feb 2015 11:08:18 -0800, Travis VanDame wrote:
> On Monday, February 16, 2015 at 12:35:00 PM UTC-6, Travis VanDame wrote:
>> I'm new to python and peewee and was looking for an example on how to
>> query a mysql table with a datetime column only returning rows that are
>> 30 days old.
>
> Well this is what I've come up with....
>
> @classmethod
> def get_archive_xml(cls, day_count):
> return cls.select().where(cls.created +
> datetime.timedelta(days=int(day_count)) >=
> datetime.date.today())
Without having actually executed your code, that looks about right.
There's probably an efficiency pickup to be had only doing the datetime
math once, but that's a technicality. Did it work?
@classmethod
def get_archive_xml(cls, day_count):
then = datetime.date.today()-datetime.timedelta(days=int(day_count))
return cls.select().where(cls.created >= then)
--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order. See above to fix.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Python & Peewee Query Example Needed Travis VanDame <tvandame@financegenius.com> - 2015-02-16 10:34 -0800
Re: Python & Peewee Query Example Needed Travis VanDame <tvandame@financegenius.com> - 2015-02-16 11:08 -0800
Re: Python & Peewee Query Example Needed Rob Gaddi <rgaddi@technologyhighland.invalid> - 2015-02-17 20:52 +0000
csiph-web