2013年7月16日火曜日

[mysql]現在時間の取得

curdate()やcurtime()関数などを使用して現在日付や時間を取得できる。

-- 現在日付(current_dateを使用してもcurdate()と同じ結果が得られる)
mysql> select curdate() ;
+------------+
| curdate()  |
+------------+
| 2013-07-16 |
+------------+
1 row in set (0.01 sec)

-- 現在時間(current_timeを使用してもcurtimeと同じ結果が得られる)
mysql> select curtime();
+-----------+
| curtime() |
+-----------+
| 08:45:46  |
+-----------+
1 row in set (0.00 sec)

-- 現在日時(current_timestampを使用してもnowと同じ結果が得られる)
mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2013-07-16 08:47:20 |
+---------------------+
1 row in set (0.00 sec)