Mysql中日期計算函式

yxyup發表於2008-03-16

Mysql中日期計算函式

1.curdate() 求當前的日期

mysql> select curdate();
+------------+
| curdate()  |
+------------+
| 2008-03-11 |
+------------+
1 row in set (0.01 sec)

2.now() 求當前日期和時間

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2008-03-11 10:16:20 |
+---------------------+
1 row in set (0.00 sec)

3.year() 提取日期中的年

mysql> select year(curdate());
+-----------------+
| year(curdate()) |
+-----------------+
|            2008 |
+-----------------+
1 row in set (0.01 sec)

4.right() 提取日期的MM-DD或是DD

mysql> select right(curdate(),5);
+--------------------+
| right(curdate(),5) |
+--------------------+
| 03-11              |
+--------------------+
1 row in set (0.01 sec)

mysql> select right(curdate(),2);
+--------------------+
| right(curdate(),2) |
+--------------------+
| 11                 |
+--------------------+
1 row in set (0.00 sec)

5.month() 提取日期中的月份

mysql> select month(curdate());
+------------------+
| month(curdate()) |
+------------------+
|                3 |
+------------------+
1 row in set (0.01 sec)

-------未完,待續

 


 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7364032/viewspace-207414/,如需轉載,請註明出處,否則將追究法律責任。

相關文章