开发者

How to print a timestamp in a human readable format in SQLite3?

I need to print a date in SQLite like this "24-03-2011 10:45:00", for now I only can print the date.

>>> import开发者_如何学JAVA sqlite3
>>> database = sqlite3.connect('basedadosteste.db')
>>> cursor = database.cursor()
>>> cursor.execute("SELECT date('now');")
<sqlite3.Cursor object at 0x00BC0710>
>>> results = cursor.fetchall()
>>> for entry in results:
...     print entry
...
(u'2011-03-25',)
>>>

Can someone give me a clue on how to do this?

Best Regards,


date only gives you the date, hence the name. If you want the date and time, you have to use datetime.

And if you want to format the date, you can use strftime - either in the SQL command, or in Python. See the sqlite3 date docs.

This would work:

SELECT strftime('%d-%m-%Y %H:%M:%S', 'now');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜