2012年1月5日木曜日

PostgreSQL 日付同士の差分をとって秒で返す

以下のように書くとできる(○○○はカラム名とか) 。
結果は秒で返る。

EXTRACT(EPOCH FROM ○○○::timestamp - △::timestamp)

例:
SELECT * FROM AAA WHERE  EXTRACT(EPOCH FROM now() - BBB::timestamp) > 100;
AAAテーブルで、現在時刻とBBBカラムに登録された時刻の差が100秒より大きいものを返す

1 件のコメント:

  1. As claimed by Stanford Medical, It's indeed the SINGLE reason this country's women get to live 10 years longer and weigh an average of 19 KG less than us.

    (And actually, it has NOTHING to do with genetics or some secret exercise and absolutely EVERYTHING about "HOW" they eat.)

    P.S, What I said is "HOW", and not "what"...

    Click this link to reveal if this short questionnaire can help you decipher your true weight loss possibility

    返信削除