Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@eiichi-worker
Last active March 27, 2017 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eiichi-worker/e97edb6b9a83a990eb64d0879355353a to your computer and use it in GitHub Desktop.
Save eiichi-worker/e97edb6b9a83a990eb64d0879355353a to your computer and use it in GitHub Desktop.
カレンダーテーブルを作る(トレジャーデータ & 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment