第九节--单行函数之日期函数

日期函数

① now 返回当前系统 日期+时间

select now();

 

② curdate() 返回当前系统日期,不包含时间

select curdate();

 

③ curtime 返回当前时间,不包含日期

select curtime();

 

④ 获取指定部分的日期,年,月,日,小时,分钟,秒

select year(now())  年;
select month(now()) 月;
select monthname(now()); #返回英文的月份

 

⑤. str_to _date 将字符通过指定的格式转换成日期。

例:

select * from employees where hiredate=str_to_date('4-3 1992', '%c-%d %Y'); #筛选出入职时间为1992-4-3的员工信息。

 

 

 

⑥date_format 将日期转换为字符

例:

1. select date_format(now(), '%y年%m月%d日') AS out_put;  #结果显示为20年04月03日
2. 查询有奖金的员工名和入职日期(xx月/xx日xx年)

select last_name, date_format(hiredate, '%m月/%d日%Y年') 入职日期 from employees where commission_pct is not null;

 

posted @ 2020-04-03 13:35  白云~  阅读(150)  评论(0编辑  收藏  举报