2019-04-10

Difference between 2 dates in SQLite3

package require tdbc::sqlite3

tdbc::sqlite3::connection create db :memory:
set statement [db prepare {SELECT CAST ((JulianDay('2019-06-14') - JulianDay('now')) as Integer) as d}]    

set diff 0
$statement foreach row {
    if {[catch {set diff [dict get $row d]}]} {
        set diff 0
    }
}

puts "The answer is $diff."

$statement close
db close

使用 SQLite3 的日期函式計算出二個日期間的差距,這裡使用 tdbc::sqlite3 測試。

沒有留言: