SQlite - . , , " ":
import datetime as dt
import peewee as pw
db = pw.SqliteDatabase('people1.db')
class Person(pw.Model):
name = pw.CharField()
birthday = pw.DateField(formats=['%Y-%m-%d'])
class Meta:
database = db
db.create_tables([Person])
Person.create(name='Bob0', birthday=dt.date(1940, 4, 13))
Person.create(name='Bob1', birthday=dt.date(1950, 5, 13))
Person.create(name='Bob2', birthday=dt.date(1960, 3, 13))
Person.create(name='Bob3', birthday=dt.date(1970, 3, 13))
Person.create(name='Bob4', birthday=dt.date(1980, 3, 13))
Person.create(name='Bob5', birthday=dt.date(1990, 3, 13))
base = Person.create(name="base", birthday=dt.date(1960, 3, 13))
for item in Person.select().where(Person.birthday > base.birthday):
print item.name , item.birthday
:
Bob3 1970-03-13
Bob4 1980-03-13
Bob5 1990-03-13
UPDATE
, .
:
SELECT
birthday,
CAST(substr(birthday, 1, instr(birthday, '/') - 1) AS integer),
CAST(substr(substr(birthday, instr(birthday, '/') + 1), 1, instr(substr(birthday, instr(birthday, '/') + 1), '/') - 1) AS integer),
CAST(substr(birthday, instr(birthday, '/') + instr(substr(birthday, instr(birthday, '/') + 1), '/') + 1) AS integer)
FROM person
:
4/13/1940 4 13 1940
12/13/1950 12 13 1950
3/3/1960 3 3 1960
3/25/1970 3 25 1970
3/13/1980 3 13 1980
3/13/1990 3 13 1990
3/13/1960 3 13 1960
:
query = """
SELECT *
FROM person
WHERE
(
substr('0000' || CAST(substr(birthday, instr(birthday, '/') + instr(substr(birthday, instr(birthday, '/') + 1), '/') + 1) AS integer), -4, 4) || '-' ||
substr('00' || CAST(substr(birthday, 1, instr(birthday, '/') - 1) AS integer), -2, 2) || '-' ||
substr('00' || CAST(substr(substr(birthday, instr(birthday, '/') + 1), 1, instr(substr(birthday, instr(birthday, '/') + 1), '/') - 1) AS integer), -2, 2)
) > '1960-03-03'
"""
for item in Person.raw(query):
print item.name, item.birthday
ISO .