postgresql日期和时间比较

时间:2025-02-23 19:50:43
select to_date('2019-01-15 18:33:42','yyyy-MM-dd hh24:mi:ss')= to_timestamp('2019-01-15 00:00:00','yyyy-MM-dd hh24:mi:ss'); >>true select to_timestamp('2019-01-15 18:33:42','yyyy-MM-dd hh24:mi:ss')- to_date('2019-01-15 18:33:42','yyyy-MM-dd hh24:mi:ss'); >>"18:33:42" select to_timestamp('2019-01-15 18:33:42','yyyy-MM-dd hh24:mi:ss')='2019/01/15'; >>false select to_date('2019-01-15 18:33:42','yyyy-MM-dd hh24:mi:ss')='2019/01/15'; >>true select to_date('2019-01-15 18:33:42','yyyy-MM-dd hh24:mi:ss')='2019-01-15'; >>true select to_date('2019-01-15 18:33:42','yyyy-MM-dd hh24:mi:ss')='20190115'; >>true select to_date('2019-01-15 18:33:42','yyyy-MM-dd hh24:mi:ss')='2019/01-15'; >>ERROR: date型の入力構文が不正です: "2019/01-15" SELECT time, to_timestamp('2011-12-13 14:15:16','yyyy-MM-dd hh24:mi:ss'), time=to_timestamp('2011-12-13 14:15:16','yyyy-MM-dd hh24:mi:ss'), time,to_date('2011-12-13 14:15:16','yyyy-MM-dd hh24:mi:ss'), time=to_date('2011-12-13 14:15:16','yyyy-MM-dd hh24:mi:ss') FROM public.product where id =21; >>"2011-12-13 14:15:16+09" >>"2011-12-13 14:15:16+09" >>true >>"2011-12-13 14:15:16+09" >>"2011-12-13" >>false