"Jordan Hayes" <[EMAIL PROTECTED]> wrote: > I just downloaded Tcl bindings for 3.3.13 and am having trouble with > some code that I wrote last year. Here's my code: > > load tclsqlite3.dll Sqlite3 > sqlite3 db foo.sqb > > set q1 "SELECT DATETIME('now','localtime','start of day') today" > db eval $q1 x { > set today $x(today) > puts "today = $today" > } > > set dq "SELECT DATETIME('$today','localtime','start of day','-1 days') > t1," > append dq " DATETIME('$today','localtime','start of day','+1 days') t3" > db eval $dq x { > set yesterday [lindex $x(t1) 0] > set tomorrow [lindex $x(t3) 0] > puts "yesterday=$yesterday tomorrow=$tomorrow" > } > > Running this script, I get this: > > today = 2007-03-20 00:00:00 > yesterday=2007-03-18 tomorrow=2007-03-20 > > Seems to be off somehow....
You appear to be apply the 'localtime' correction twice: once when you initially compute "today" and then again before you apply the "-1 day" and "+1 day" operators. A date in SQLite is not an object that keeps a separate hidden "actual date" behind the scenes. A date is just a string. When you apply 'localtime' it does not set some display flag - it actually changes the string. So you can apply 'localtime' multiple times and it will keep shifting the date. For example, consider this SQL: SELECT 111, datetime('now'); SELECT 222, datetime('now','localtime'); SELECT 333, datetime('now','localtime','localtime'); SELECT 444, datetime('now','localtime','localtime','localtime'); The output is: 111|2007-03-21 01:44:03 222|2007-03-20 21:44:03 333|2007-03-20 17:44:03 444|2007-03-20 13:44:03 With that in mind, go back and remove the extra 'localtime' modifier and I think your code will work. -- D. Richard Hipp <[EMAIL PROTECTED]> ----------------------------------------------------------------------------- To unsubscribe, send email to [EMAIL PROTECTED] -----------------------------------------------------------------------------