4、MYSQL常用函数(日期和时间函数)

目录

 curdate():返回当前日期

 curtime():返回当前时间

 now():返回当前日期和时间

unix_timestamp(date):返回date的unix时间函数

 from_unixtime:返回inix时间戳的日期值

 week/year/monthname(date):日期date为一年内第几周/日期年份/月份

hour/minute(time):返回time小时值/分钟值

DATE_FORMAT(date,fmt):返回date字符化为fmt的日期值

 DATE_ADD(date,interval expr type):返回一个日期值或时间值加上一个时间间隔的时间数字

 datediff(expr,expr2):起始时间和结束时间expr2之间的天数


 curdate():返回当前日期

 select CURDATE();

 curtime():返回当前时间

select CURTIME();

 now():返回当前日期和时间

select NOW();

unix_timestamp(date):返回date的unix时间函数

时间戳:从格林威治时间1970年01月01日00时00分00秒起至现在的总秒数 

 from_unixtime:返回inix时间戳的日期值

select FROM_UNIXTIME(1684134516) ;

 

week/year/monthname(date):日期date为一年内第几周/日期年份/月份

select WEEK(now()),YEAR(now());

hour/minute(time):返回time小时值/分钟值

select HOUR(CURTIME()),MINUTE(CURTIME()),MONTHNAME(now());

DATE_FORMAT(date,fmt):返回date字符化为fmt的日期值

MySQL date_format()函数 - MySQL教程 (yiibai.com)

 

 

 DATE_ADD(date,interval expr type):返回一个日期值或时间值加上一个时间间隔的时间数字

select now() current,date_add(now(),INTERVAL  31 day) after31days,
date_add(now(),INTERVAL  '1_2' year_month) after_oneyear_twomonth;

select now() current,date_add(now(),INTERVAL  -31 day) after31days,
date_add(now(),INTERVAL  '-1_-2' year_month) after_oneyear_twomonth;

 

 

datediff(expr,expr2):起始时间和结束时间expr2之间的天数

select DATEDIFF('2008-08-08',now());

猜你喜欢

转载自blog.csdn.net/weixin_62190821/article/details/128485793