Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
カレンダーテーブルを作る(トレジャーデータ & Mysql)

カレンダーテーブルを作る(トレジャーデータ & Mysql)

トレジャーデータ上でカレンダーテーブルを作る

SELECT
  TD_TIME_FORMAT(TD_TIME_ADD(TD_SCHEDULED_TIME(), CONCAT('-',s.s,'d')), 'yyyy-MM-dd','JST') AS d
FROM (
  SELECT
    GENERATE_SERIES(0, 7) AS s
) AS s

Mysql上でカレンダーテーブルを作る

ネタ元
https://developers.eure.jp/tech/mysql_tips1/

 SELECT
    DATE_FORMAT(DATE_SUB(NOW(), INTERVAL series_numbers.number DAY),'%Y-%m-%d') AS date
  FROM (
    SELECT @num := 0 AS number
    UNION ALL
    SELECT @num := @num + 1 FROM information_schema.COLUMNS
	LIMIT 7
  ) AS series_numbers
@eiichi-worker

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment