This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author p-ganssle
Recipients berker.peksag, ghaering, jondo, p-ganssle
Date 2018-11-02.20:00:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1541188812.1.0.788709270274.issue35145@psf.upfronthosting.co.za>
In-reply-to
Content
According to the sqlite documentation, there's no fundamental datetime type in sqlite: https://www.sqlite.org/datatype3.html#date_and_time_datatype


    SQLite does not have a storage class set aside for storing dates
    and/or times. Instead, the built-in Date And Time Functions of SQLite
    are capable of storing dates and times as TEXT, REAL, or INTEGER values


If you have an arbitrary database whose schema you don't know, I'm not sure it would be possible to automatically determine that it's a datetime, though it appears that Python already provides this functionality by exposing the converters "date" and "timestamp" ( https://docs.python.org/3/library/sqlite3.html#default-adapters-and-converters )

If you don't know the schema you can't be 100% accurate on which columns are datetime, but apparently datetime types that are text will be of the format "YYYY-MM-DD HH:MM:SS.SSS", which is a variant of iso8601, REAL columns will be Julian day numbers and integers will be epoch time.

If you assume that all your datetime columns will be TEXT and that any TEXT column that happens to be a valid date of is a datetime column, then you can either use:

    datetime.strftime(text_column, "%Y-%m-%d %H:%M:%S.%f")

Or if you want to be faster and less strict (this will allow several other variations on ISO 8601):

    datetime.fromisoformat(text_column)

I would not recommend using `dateutil.parser.parse`, as the dateutil parser is intended for taking something you know to be a string representing a datetime and getting you a datetime object from it. It is not designed to tell you whether something is or is not a datetime.
History
Date User Action Args
2018-11-02 20:00:12p-gansslesetrecipients: + p-ganssle, ghaering, berker.peksag, jondo
2018-11-02 20:00:12p-gansslesetmessageid: <1541188812.1.0.788709270274.issue35145@psf.upfronthosting.co.za>
2018-11-02 20:00:12p-gansslelinkissue35145 messages
2018-11-02 20:00:11p-gansslecreate