mysql学习笔记003

(17)使用日期函数

mysql> update sales_rep set date_joined='2015-03-16',birthday="1988-05-04" where employee_number=1;

(18)指定日期格式

标准的日期格式是:YYYY-MM-DD,指定日期格式的函数date_format()

%m:01-12,%d:01-31,%y:四位数的年份

mysql> select date_format(date_joined,'%m/%d/%y') from sales_rep where employee_number=1;
+-------------------------------------+
| date_format(date_joined,'%m/%d/%y') |
+-------------------------------------+
| 03/16/15                            |
+-------------------------------------+

%W:返回星期日期,%M:返回月份的名字 ,%e:显示日期01-31,

%a:星期日期的缩写,%D:带后缀的日期,%b:缩写的月份的名字,%y:四位数的年份


mysql> select date_format(date_joined,'%W %M %e %Y') from sales_rep where employee_number=1;
+----------------------------------------+
| date_format(date_joined,'%W %M %e %Y') |
+----------------------------------------+
| Monday March 16 2015                   |
+----------------------------------------+


mysql> select date_format(date_joined,'%a %D %b %Y') from sales_rep where employee_number=1;
+----------------------------------------+
| date_format(date_joined,'%a %D %b %Y') |
+----------------------------------------+
| Mon 16th Mar 2015                      |
+----------------------------------------+

(19)返回当前日期和时间

mysql> select now(),current_date();
+---------------------+----------------+
| now()               | current_date() |
+---------------------+----------------+
| 2015-03-16 22:46:46 | 2015-03-16     |
+---------------------+----------------+

mysql> select year(birthday) from sales_rep;
+----------------+
| year(birthday) |
+----------------+
|           1988 |
|           1980 |
|           1989 |
|           1989 |
|           1984 |
|           1984 |
|           1984 |
|           1984 |
+----------------+


mysql> select month(birthday),dayofmonth(birthday)  from sales_rep;
+-----------------+----------------------+
| month(birthday) | dayofmonth(birthday) |
+-----------------+----------------------+
|               5 |                    4 |
|               5 |                    4 |
|               5 |                    4 |
|               5 |                    4 |
|               5 |                    4 |
|               6 |                    4 |
|               6 |                    5 |
|               2 |                    5 |
+-----------------+----------------------+



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值