Mysql日期转换函数、时间转换函数

本文详细介绍了MySQL中获取当前日期时间、日期转换、时间转换、日期时间计算及时区转换的相关函数,包括now()、sysdate()、date_format()、str_to_date()、to_days()、maketime()等,以及date_add()、date_sub()、datediff()等计算函数,对于数据库操作和时间处理非常实用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、MySQL 获得当前日期时间 函数

1,获得当前日期+时间(date + time)函数:now():

select now();
结果:2008-08-08 22:20:46

2,获得当前日期+时间(date + time)函数:sysdate()
sysdate() 日期时间函数跟 now() 类似,不同之处在于:now() 在执行开始时值就得到了, sysdate() 在函数执行时动态得到值;

select sysdate();
结果:2008-08-08 22:20:46

3,MySQL 获得当前时间戳函数:current_timestamp, current_timestamp():

select current_timestamp, current_timestamp();
结果:2008-08-09 23:22:24 , 2008-08-09 23:22:24

二、MySQL 日期转换函数、时间转换函数

1,MySQL Date/Time to Str(日期/时间转换为字符串)函数:date_format(date,format), time_format(time,format):

函数:date_format('2008-08-08 22:23:01', '%Y%m%d%H%i%s')
结果:20080808222301 

MySQL 日期、时间转换函数:date_format(date,format), time_format(time,format) 能够把一个日期/时间转换成各种各样的字符串格式。它是 str_to_date(str,format) 函数的 一个逆转换。

2,MySQL Str to Date (字符串转换为日期)函数:str_to_date(str, format):

select str_to_date('08/09/2008', '%m/%d/%Y'); -- 2008-08-09
select str_to_date('08/09/08' , '%m/%d/%y'); -- 2008-08-09
select str_to_da
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值