mysql 日期
數據類型
| 數據類型 | 格式 |
| date | YYYY-MM-DD |
| datetime | YYYY-MM-DD HH:MM:SS |
| timestamp | YYYY-MM-DD HH:MM:SS |
| year | YYYY 或 YY |
具體實現的函數
1、now()?返回當前的日期和時間
SELECT NOW();2、curdate()?返回當前的日期
SELECT CURdate();3、curtime()返回當前的時間
SELECT CURtime();
4、date()?提取日期或日期/時間表達式的日期部分
SELECT date('2016-08-12 15:33:22');此外還有:
select time('2016-08-12 15:33:22');??????? -- 15:33:22?
select year(@dt)、select quarter(@dt)、select month(@dt)、select week(@dt)、select day(@dt)、select hour(@dt)、select minute(@dt)、select second(@dt)?
5、extract()?返回日期/時間按的單獨部分
SELECT extract( year from '2016-08-12 15:33:22');此外還有:select extract(quarter ?from @dt)、select extract(month from @dt)、select extract(week from @dt)、select extract(day from @dt)、?select extract(hour ?from @dt)、select extract(minute ?from @dt)、select extract(second ?from @dt)
6、date_format(date,format)?用不同的格式顯示日期/時間
SELECT DATE_FORMAT('2016-08-12 15:33:22','%y/%m/%d')轉載于:https://www.cnblogs.com/sker/p/5765265.html
總結
- 上一篇: 创建和销毁对象
- 下一篇: mysql在空闲8小时之后会断开连接(默