Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85775
| From | "Frank Millman" <frank@chagford.com> |
|---|---|
| Subject | Re: sqlite3 and dates |
| Date | 2015-02-18 10:22 +0200 |
| References | <mc1atd$cq0$1@ger.gmane.org> <mc1g3n$q8j$1@ger.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18809.1424247734.18130.python-list@python.org> (permalink) |
"Mark Lawrence" <breamoreboy@yahoo.co.uk> wrote in message
news:mc1g3n$q8j$1@ger.gmane.org...
> On 18/02/2015 06:19, Frank Millman wrote:
>> Hi all
>>
>> sqlite3 does not have a DATE type, but the python module does a pretty
>> good
>> job of providing one -
>>
>> However, the following does not return a date object -
>>
>>>>> cur.execute('SELECT CAST(? AS DATE)', ('2015-03-31',))
>> <sqlite3.Cursor object at 0x00FE9BE0>
>>>>> cur.fetchone()
>> (2015,)
>>>>>
>>
>
> Will this do?
>
> cur.execute('select current_date as "d [date]", current_timestamp as "ts
> [timestamp]"')
> row = cur.fetchone()
> print("current_date", row[0], type(row[0]))
> print("current_timestamp", row[1], type(row[1]))
>
I will have to experiment a bit, It looks as if it will do just fine.
The magic incantation is
'detect_types=sqlite3.PARSE_DECLTYPES|PARSE_COLNAMES'
I had not looked at PARSE_COLNAMES before. Very useful.
Thanks, Mark
Frank
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: sqlite3 and dates "Frank Millman" <frank@chagford.com> - 2015-02-18 10:22 +0200
csiph-web