2
2

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 1 year has passed since last update.

Athenaで先月月初、先月月末、今月月初、今月月末を出す

Posted at

Athenaで日付周りの扱いでハマったので備忘録です。
current_dateではうまく行かず。current_timestampを使うのがポイント。

-- Athena 先月、今月
SELECT 
   date_trunc('month', current_timestamp) - interval '1' month                      AS "先月月初",
   date_trunc('month', current_timestamp) - interval '1' day                        AS "先月月末",
   date_trunc('month', current_timestamp)                                           AS "今月月初",
   date_trunc('month', current_timestamp) + interval '1' month - interval '1' day   AS "今月月末"
;

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?