Comments on: Trouble Getting a DateWherein I write some stuff that you may like to read. Or not, its up to you really.By: David Welden- May 10, 2008 Glad to know I am not the only one who always trips over this, but I always figured it is because dates are so rarely used in real world programming One of the few ugly warts in Python I don&8217;t like to discuss with the unbelievers. Absolutely this mess needs to be cleaned up, preferably in a new class that consolidates the intended functionality of all of the different standard modules. &8220;Preferably one way to do things&8221;, nohttp://halfcooked.com/blog/2008/05/09/trouble-getting-a-date/#comment-32822 By: T Middleton- May 9, 2008 PostgreSQL has nice &8220;timestamp&8221;, &8220;interval&8221;, &8220;date&8221; and &8220;time&8221; datatypes, and decent functions for date mathmanipulation (up to microsecond resolution). I usually do most of my date mathformating inside my postgresql queries for this reason and just have it spit out text for python. Kind of sad in a way, but better than some of your frustration above for my uses.http://halfcooked.com/blog/2008/05/09/trouble-getting-a-date/#comment-32787 By: Ira- May 9, 2008 Just to make things a little more confusing, SQL Server has a timestamp data type&8230; but it doesn&8217;t even remotely conform to ANSIISO standards. Instead, it&8217;s a synonym for rowversion. And to confirm, SQL Server only provides datetime (and smalldatetime, half the size but less precision).http://halfcooked.com/blog/2008/05/09/trouble-getting-a-date/#comment-32783 By: Mariano- May 9, 2008 Andy, you need to use &8220;date&8221; or &8220;timestamp&8221; (I think it matters if you write it lowercase or uppercase) as the sqlite&8217;s datatype to make it work (this comes by default in sqlite3 but you can write an adapterconverter to build whatever datatype you want to store). See sqlite3&8217;s doc for more on this: http:docs.python.orglibnode348.htmlhttp://halfcooked.com/blog/2008/05/09/trouble-getting-a-date/#comment-32780 By: Laurence Rowe- May 9, 2008 Leave stftime, strptime as they are, any coming from C (or indeed php) expects them to work that way. The datetime library is great, none of the dbapi drivers I know use mx.DateTime anymore. Add pytz to get timezone support. If you are working with relational databases, then give SQLAlchemy a try.http://halfcooked.com/blog/2008/05/09/trouble-getting-a-date/#comment-32776 By: Marius Gedminas- May 9, 2008 Your blog is not escaping less-than and greater-than characters, so browsers interpret them as strange malformed HTML elements named &8220;type&8221;.http://halfcooked.com/blog/2008/05/09/trouble-getting-a-date/#comment-32768 By: Dominic Brooks- May 9, 2008 In addition to DATE, Oracle has had TIMESTAMP and INTERVAL since 9i. Doesn&8217;t make things any easier for you though.http://halfcooked.com/blog/2008/05/09/trouble-getting-a-date/#comment-32765 By: Andy Todd- May 9, 2008 Mariano, I didn&8217;t know about PARSE_DECLTYPES so I added it to my sample code above, and got a nice error message when I tried to retrieve my data; n 17: curs.execute("SELECT FROM date_test") --------------------------------------------------------------------------- Traceback (most recent call last) WorkPython in () SystemLibraryFrameworksPython.frameworkVersions2.5libpython2.5sqlite3dbapi2.py in convert_date(val) 61 62 def convert_date(val): --- 63 ...http://halfcooked.com/blog/2008/05/09/trouble-getting-a-date/#comment-32762 By: Mariano- May 9, 2008 Umm it seems it doesn&8217;t get print, anyway give it a tryhttp://halfcooked.com/blog/2008/05/09/trouble-getting-a-date/#comment-32757 By: Mariano- May 9, 2008 Sorry, I missed the output from print type(r0): type(r0)http://halfcooked.com/blog/2008/05/09/trouble-getting-a-date/#comment-32756 |