YanoRyuichi.com/
Wiki
Blog
GitHub
Sandbox
開始行:
* MySQL SQL 日付関連 [#c3d6086c]
** 月末 [#p6cca634]
SELECT LAST_DAY(NOW());
** 月初 [#ca6972b7]
SELECT DATE_FORMAT(NOW(), '%Y-%m-01');
** 2週間後 (INTERVAL) [#e2f759bb]
SELECT NOW() + INTERVAL 2 WEEK;
** 日数の差 [#m27fd466]
SELECT DATEDIFF(CAST('2014-12-31' AS date), CAST('2014-1...
=> 60
http://dev.mysql.com/doc/refman/5.6/en/date-and-time-func...
** タイムスタンプを日付にキャスト [#z19f3b30]
SELECT DATE(NOW());
** 部分フィールドの取得 [#x1bd1911]
SELECT EXTRACT(YEAR FROM '1999-07-02');
*** INT(またはString)型の年月日からDate型の日付を作る [...
SELECT STR_TO_DATE(CONCAT(year,'-',month,'-',day), '%Y-%...
- http://dev.mysql.com/doc/refman/5.6/en/date-and-time-fu...
- http://dev.mysql.com/doc/refman/5.6/en/date-and-time-fu...
** 書式指定 DATE_FOMRMAT() [#y1198289]
SELECT DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:00');
+-----------------------------------------+
| DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:00') |
+-----------------------------------------+
| 2015-06-02 03:41:00 |
+-----------------------------------------+
http://dev.mysql.com/doc/refman/5.6/en/date-and-time-func...
** 参考 [#vf47705a]
- http://dev.mysql.com/doc/refman/5.1-olh/ja/date-and-tim...
- http://dev.mysql.com/doc/refman/5.6/en/date-and-time-fu...
終了行:
* MySQL SQL 日付関連 [#c3d6086c]
** 月末 [#p6cca634]
SELECT LAST_DAY(NOW());
** 月初 [#ca6972b7]
SELECT DATE_FORMAT(NOW(), '%Y-%m-01');
** 2週間後 (INTERVAL) [#e2f759bb]
SELECT NOW() + INTERVAL 2 WEEK;
** 日数の差 [#m27fd466]
SELECT DATEDIFF(CAST('2014-12-31' AS date), CAST('2014-1...
=> 60
http://dev.mysql.com/doc/refman/5.6/en/date-and-time-func...
** タイムスタンプを日付にキャスト [#z19f3b30]
SELECT DATE(NOW());
** 部分フィールドの取得 [#x1bd1911]
SELECT EXTRACT(YEAR FROM '1999-07-02');
*** INT(またはString)型の年月日からDate型の日付を作る [...
SELECT STR_TO_DATE(CONCAT(year,'-',month,'-',day), '%Y-%...
- http://dev.mysql.com/doc/refman/5.6/en/date-and-time-fu...
- http://dev.mysql.com/doc/refman/5.6/en/date-and-time-fu...
** 書式指定 DATE_FOMRMAT() [#y1198289]
SELECT DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:00');
+-----------------------------------------+
| DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:00') |
+-----------------------------------------+
| 2015-06-02 03:41:00 |
+-----------------------------------------+
http://dev.mysql.com/doc/refman/5.6/en/date-and-time-func...
** 参考 [#vf47705a]
- http://dev.mysql.com/doc/refman/5.1-olh/ja/date-and-tim...
- http://dev.mysql.com/doc/refman/5.6/en/date-and-time-fu...
ページ名: