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')

posted @ 2016-08-12 15:49  珍真小心  阅读(180)  评论(0编辑  收藏  举报