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.

BigQueryで当月最終日を取り出す

Last updated at Posted at 2017-11-11

BigQueryのtimestamp型の値から、その日付が属する月の日数を取り出す方法を考えてみました。レガシーではない方のSQLを使っています。

SELECT EXTRACT(
  DAY FROM DATE_SUB(
    DATE_ADD(
      DATE_TRUNC(DATE(TIMESTAMP "2000-02-01 01:23:45"), MONTH),
      INTERVAL 1 MONTH
    ),
    INTERVAL 1 DAY
  )
)

どうにも冗長っぽいのですが、これより短くできませんでした。

参考URL

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?