LoginSignup
54
51

More than 5 years have passed since last update.

【MySQL】日時の計算(加算・減算)

Posted at

例:

"SELECT count(id) as cnt FROM table  
WHERE (date > (NOW() - INTERVAL 60 SECOND)",

上記SQLは、dateカラムにある値が、現在時刻から60秒前以降の値のidの数を数えるものです。

INTERVALの前にマイナス-・プラス+記号をつけることで、減算・加算ができます。

+(-) INTERVAL 数値 単位 という構文になります。

単位は、

MICROSECOND
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH

など

54
51
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
54
51