【MySQL】函数

在这里插入图片描述

点赞👍👍收藏🌟🌟关注💖💖
你的支持是对我最大的鼓励,我们一起努力吧!😃😃

在mysql中其实内置了很多的函数操作,这些函数可以让我们在数据统计的时候以及查表的时候进行各自各样的操作。

1.日期函数

函数名称 描述
current_date() 当前日期
current_time() 当前时间
current_timestamp() 当前时间戳
date(datetime) 返回datetime参数的日期部分
date_add(date,interval d_value_type) 在date中添加日期或者时间 ,interval后的数值单位可以是:year、minute、second、day
date_sub(date,interval d_value_type) 在date中减去日期或者时间 ,interval后的数值单位可以是:year、minute、second、day
datediff(date1,date2) 两个日期的差,单位是天
now() 当前日期时间

获得当前日期(年月日)

select current_date();

在这里插入图片描述

获得当前时间(时分秒)

select current_time();

在这里插入图片描述

获得当前时间戳

select current_timestamp();

在这里插入图片描述

获得当前日期时间

select now();

在这里插入图片描述

截断当前时间,只获得日期部分

select date(now());

函数中可以嵌套函数

在这里插入图片描述

在日期的基础上加日期

select date_add(now(),interval 10 year);

在这里插入图片描述

在日期的基础上减去时间

<
评论 122
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值