select GETDATE(),NOW() FROM t_表名;
select curdate(),NOW() FROM TB_表名;
select (NOW()-日期时间字段) FROM T_表名;
select (curdate()-日期时间字段) FROM T_表名;
select datediff(year, 开始日期,结束日期) FROM T_表名;;
select datediff(quarter, 开始日期,结束日期) FROM T_表名;
select datediff(month, 开始日期,结束日期) from 表名;
select datediff(day, 开始日期,结束日期) FROM T_表名;
select datediff(week, 开始日期,结束日期) FROM T_表名;
select datediff(hour, 开始日期,结束日期) FROM T_表名;
select datediff(minute, 开始日期,结束日期) FROM T_表名;
select datediff(second, 开始日期,结束日期) FROM T_表名;
select (CURDATE() - 6) as dateList
union
select (CURDATE() - 5) as dateList
union
select (CURDATE() - 4) as dateList
union
select (CURDATE() - 3) as dateList
union
select (CURDATE() - 2) as dateList
union
select (CURDATE() - 1) as dateList
union
select (CURDATE() - 0) as dateList
SELECT NOW(), CURDATE(), CURTIME()
CONVERT 可以把字符串转换成int
ORDER BY m.ENTERPRISE_CODEID DESC
, CONVERT(INT,d.GAS_MONTH)
select QUARTER( curdate() );
select DATE_SUB(CURDATE(),INTERVAL 1 DAY);
select DATE_ADD(CURDATE(),INTERVAL 1 DAY);
SELECT
curdate() AS 当前年月日,
NOW() AS 当前年月日_时分秒,
date_format( NOW(), '%a' ) AS 星期几,
date_format( NOW(), '%b' ) AS 几月,
date_format( NOW(), '%c' ) AS 月,
date_format( NOW(), '%D' ) AS 当月的第几天带后缀,
date_format( NOW(), '%e' ) AS 当月的第几天,
date_format( NOW(), '%f' ) AS 微妙,
date_format( NOW(), '%H' ) AS 小时,
date_format( NOW(), '%i' ) AS 分钟,
date_format( NOW(), '%j' ) AS 一年的第几天,
date_format( NOW(), '%M' ) AS 月份全称,
date_format( NOW(), '%p' ) AS 上午或下午,
date_format( NOW(), '%S' ) AS 秒,
date_format( NOW(), '%U' ) AS 一年的第几周,
date_format( NOW(), '%W' ) AS 星期全称,
date_format( NOW(), '%Y' ) AS 年,
date_format( NOW(), '%Y-%m-%d' ) AS 年月日,
date_format( NOW(), '%Y-%m-%d %H:%i:%s' ) AS 年月日_时分秒,
QUARTER ( NOW() ) AS 季度
好的代码像粥一样,都是用时间熬出来的