0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SQLで今日から半年前・半年後のDATETIMEを取得する

Last updated at Posted at 2018-07-04

たまに条件として使うことがあるので、備忘録として。

今日から半年前の00:00:00

CURDATE() - INTERVAL 6 month + INTERVAL 0 second;

例)今日が2018年07月04日の場合、「2018-01-04 00:00:00」

今日から半年後の00:00:00

CURDATE() + INTERVAL 6 month + INTERVAL 0 second;

例)今日が2018年07月04日の場合、「2019-01-04 00:00:00」

今日から半年後の23:59:59

CURDATE() + INTERVAL 6 month + INTERVAL 1 day - INTERVAL 1 second;

例)今日が2018年07月04日の場合、「2019-01-04 23:59:59」

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?