在MySQL中更改curdate()(当前日期)格式
当前日期格式为“YYYY-mm-dd”。要更改当前日期格式,可以使用date_format()。
让我们首先显示当前日期-
mysql> select curdate();
这将产生以下输出-
+------------+ | curdate() | +------------+ | 2019-08-08 | +------------+ 1 row in set (0.00 sec)
以下是更改curdate()(当前日期)格式的查询-
mysql> select date_format(curdate(), '%m/%d/%Y');
这将产生以下输出-
+------------------------------------+ | date_format(curdate(), '%m/%d/%Y') | +------------------------------------+ | 08/08/2019 | +------------------------------------+ 1 row in set (0.00 sec)
让我们首先创建一个表-
mysql> create table DemoTable ( ArrivalDate date );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('2019-01-10');
mysql> insert into DemoTable values('2016-12-18');使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-------------+ | ArrivalDate | +-------------+ | 2019-01-10 | | 2016-12-18 | +-------------+ 2 rows in set (0.00 sec)
以下是更改日期格式的查询-
mysql> select date_format(ArrivalDate, '%m/%d/%Y') from DemoTable;
这将产生以下输出-
+--------------------------------------+ | date_format(ArrivalDate, '%m/%d/%Y') | +--------------------------------------+ | 01/10/2019 | | 12/18/2016 | +--------------------------------------+ 2 rows in set (0.00 sec)
热门推荐
10 生日祝福语朋友简短的话
11 宝贝的人生祝福语简短
12 新年有哪些祝福语简短
13 简短又洋气祝福语大全
14 简短祝福语除夕快乐英文
15 生日贺卡祝福语毕业简短
16 战友聚会祝福语幽默简短
17 最新中秋祝福语简短英语
18 夏日升学宴祝福语简短