Gilles Ganault wrote:
> I read http://www.sqlite.org/lang_datefunc.html, but I still don't
> know how to extract the year from a table where a column has dates
> formatted as YYYY-MM-DD.

select strftime('%Y', myDateColumn) from myTable;

> Currently, I use this, but I'm sure there's a better way:
>
> ======
> //Find all invoices sent in 2009
> SELECT * FROM invoices,phones WHERE phones_nbr=invoices_phones_nbr AND
> invoices_date_sent GLOB '2009-*'
> ======

That'll work too. Also

substr(invoices_date_sent, 1, 4) = '2009'
-- or
invoices_date_sent >= '2009' and invoices_date_sent < '2010'

The last one is probably the fastest, and can use a suitable index.

Igor Tandetnik 



_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to