Created
July 19, 2019 06:58
-
-
Save mugyu/ff7bb54edd3451db8d266838227cca55 to your computer and use it in GitHub Desktop.
MySQLの日付関連フォーマット in PHP。多分、他のデータベースでも使えると思うけど、どうなんだろう?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('DATE_MySQL_DATE', 'Y-m-d'); | |
define('DATE_MySQL_TIME', 'H:i:s'); | |
define('DATE_MySQL_YEAR', 'Y'); | |
define('DATE_MySQL_DATETIME', DATE_MySQL_DATE . ' ' . DATE_MySQL_TIME); | |
$now = time(); | |
echo date(DATE_ATOM, $now), "\n"; // => 2019-07-19T15:51:27+09:00 | |
echo date(DATE_RSS, $now), "\n"; // => Fri, 19 Jul 2019 15:51:27 +0900 | |
echo date(DATE_MySQL_DATE, $now), "\n"; // => 2019-07-19 | |
echo date(DATE_MySQL_TIME, $now), "\n"; // => 15:51:27 | |
echo date(DATE_MySQL_YEAR, $now), "\n"; // => 2019 | |
echo date(DATE_MySQL_DATETIME, $now), "\n"; // => 2019-07-19 15:51:27 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment