mysql中的时间year/date/time/datetime
year:
mysql> create table y(y year);
Query OK, 0 rows affected (0.03 sec) mysql> desc y;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| y | year(4) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
1 row in set (0.00 sec) mysql> insert into y values(1987);
Query OK, 1 row affected (0.00 sec) mysql> select * from y;
+------+
| y |
+------+
| 0000 |
| 0000 |
| 1987 |
+------+
3 rows in set (0.00 sec) mysql> insert into y values(19874);
Query OK, 1 row affected, 1 warning (0.00 sec) mysql> select * from y;
+------+
| y |
+------+
| 0000 |
| 0000 |
| 1987 |
| 0000 |
+------+
4 rows in set (0.00 sec)
date:
mysql> create table d(d date);
Query OK, 0 rows affected (0.02 sec) mysql> insert into d(1);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual th
corresponds to your MariaDB server version for the right syntax to use near '
at line 1
mysql> insert into d values(1);
Query OK, 1 row affected, 1 warning (0.00 sec) mysql> select * from d;
+------------+
| d |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec) mysql> insert into d values(10-15);
Query OK, 1 row affected, 1 warning (0.01 sec) mysql> select * from d;
+------------+
| d |
+------------+
| 0000-00-00 |
| 0000-00-00 |
+------------+
2 rows in set (0.00 sec) mysql> insert into d values(2011-7-7);
Query OK, 1 row affected, 1 warning (0.00 sec) mysql> select * from d;
+------------+
| d |
+------------+
| 0000-00-00 |
| 0000-00-00 |
| 0000-00-00 |
+------------+
3 rows in set (0.00 sec) mysql> insert into d values(2017-10-15);
Query OK, 1 row affected, 1 warning (0.00 sec) mysql> select * from d;
+------------+
| d |
+------------+
| 0000-00-00 |
| 0000-00-00 |
| 0000-00-00 |
| 0000-00-00 |
+------------+
4 rows in set (0.00 sec) mysql> insert into d values('2011-7-7');
Query OK, 1 row affected (0.00 sec) mysql> select * from d;
+------------+
| d |
+------------+
| 0000-00-00 |
| 0000-00-00 |
| 0000-00-00 |
| 0000-00-00 |
| 2011-07-07 |
+------------+
5 rows in set (0.00 sec) mysql>
要用字符串型式插入
time:
mysql> create table t(t time);
Query OK, 0 rows affected (0.03 sec) mysql> insert into t values(12345);
Query OK, 1 row affected (0.00 sec) mysql> select * from t;
+----------+
| t |
+----------+
| 01:23:45 |
+----------+
1 row in set (0.00 sec) mysql> insert into t values(1234511111);
Query OK, 1 row affected, 1 warning (0.00 sec) mysql> select * from t;
+----------+
| t |
+----------+
| 01:23:45 |
| 00:00:00 |
+----------+
2 rows in set (0.00 sec) mysql> insert into t values('09:09:09');
Query OK, 1 row affected (0.00 sec) mysql> select * from t;
+----------+
| t |
+----------+
| 01:23:45 |
| 00:00:00 |
| 09:09:09 |
+----------+
3 rows in set (0.00 sec) mysql>
datetime:
mysql> create table dt(dt datetime);
Query OK, 0 rows affected (0.03 sec) mysql> insert into dt values('2017-01-01 0:0:01');
Query OK, 1 row affected (0.00 sec) mysql> select * from dt;
+---------------------+
| dt |
+---------------------+
| 2017-01-01 00:00:01 |
+---------------------+
1 row in set (0.00 sec) mysql> insert into dt values('1234567890');
Query OK, 1 row affected, 1 warning (0.00 sec) mysql> select * from dt;
+---------------------+
| dt |
+---------------------+
| 2017-01-01 00:00:01 |
| 0000-00-00 00:00:00 |
+---------------------+
2 rows in set (0.00 sec) mysql>
mysql中的时间year/date/time/datetime的更多相关文章
- mysql中对于时间的处理,时间的滚动,求时间间隔,切换时区等等
mysql中对于时间的处理,时间的滚动,求时间间隔,切换时区等等 在mysql的使用过程中,有时候会出现对时间进行的操作,比如时间向前向后滚动,求2个时间的间隔,或者切换时区的操作 1,时间向前滚动( ...
- sql点滴42—mysql中的时间转换
原文:sql点滴42-mysql中的时间转换 UNIX时间戳转换为日期用函数: FROM_UNIXTIME() select FROM_UNIXTIME(1156219870); 日期转换为UNIX时 ...
- 小程序 js中获取时间new date()的用法(网络复制过来自用)
js中获取时间new date()的用法 获取时间: 1 var myDate = new Date();//获取系统当前时间 获取特定格式的时间: 1 myDate.getYear(); //获 ...
- Js中获取时间 new date()的用法
Js中获取时间 new date()的用法 获取时间: var myDate = new Date();//获取系统当前时间 myDate.getYear(); //获取当前年份(2位) myDate ...
- MySql中的时间类型datetime,timestamp,date,year比较
MySQL日期类型.日期格式.存储空间.日期范围比较.日期类型 存储空间 日期格式 日期范围------------ --------- ...
- MySQL 时间类型 DATE、DATETIME和TIMESTAMP
1.DATE.DATETIME和TIMESTAMP 表达的时间范围 Type Range Remark DATE '1000-01-01' to '9999-12-31' 只有日期部分,没有时间部分 ...
- Java向mysql中插入时间的方法
ava向MySQL插入当前时间的四种方式和java时间日期格式化的几种方法(案例说明);部分资料参考网络资源 java向MySQL插入当前时间的四种方式 第一种:将java.util.Date类型的 ...
- MySQL中的时间问题
MySQL 获得当前日期时间 函数 获得当前日期+时间(date + time)函数:now() mysql> select now(); +---------------------+ | n ...
- MYSQL中的时间类型
时间上总共有五中表示方法:它们分别是 time.date.datetime.timestamp和year. time : “hh:mm:ss”格式表示的时间值,格式显示TIME值,但允许使用字符串或 ...
随机推荐
- 我们在删除SQL Sever某个数据库表中数据的时候,希望ID重新从1开始,而不是紧跟着最后一个ID开始需要的命令
一.如果数据重要,请先备份数据 二.删除表中数据 SQL: Delete From ('表名') 如:Delete From abcd 三.执行新语句 SQL: dbcc checkident('表 ...
- [socket编程] 一个服务器与多个客户端之间通信
转自:http://blog.csdn.net/neicole/article/details/7539444 并加以改进 Server程序: // OneServerMain.cpp #includ ...
- 在ios 上 按钮 disabled 样式显示异常
将input,button或textarea设置为disabled后,在iphone手机上样式将被覆写-webkit-appearance:none; 文字的颜色还是灰色. 原本在android 上 ...
- springBoot定制内嵌的Tomcat
此篇仅介绍配置方式,详细配置内容百度查阅 工程结构: 可以通过配置的方式设置参数,如下 application.properties #配置tomcat端口 # server.port= 8888 # ...
- 【bzoj2100】[Usaco2010 Dec]Apple Delivery 最短路
题目描述 Bessie has two crisp red apples to deliver to two of her friends in the herd. Of course, she tr ...
- python-输出颜色显示
显示颜色格式:\033[显示方式;字体色;背景色m...主题内容hello world...\033[0m \033 从这里开始标颜色................................. ...
- hadoop 使用map将SequenFile里的小文件解压出来
上例中将HDFS里小文件通过mapper压缩到一个文件中,本例将这些小文件解压出来. mapreduce可以按SequenceFile的key进行分片. 1.mapper public class M ...
- [Violet]天使玩偶
description Ayu 在七年前曾经收到过一个天使玩偶,当时她把它当作时间囊埋在了地下.而七年后 的今天,Ayu 却忘了她把天使玩偶埋在了哪里,所以她决定仅凭一点模糊的记忆来寻找它. 我们把 ...
- [洛谷P4688][Ynoi2016]掉进兔子洞
题目大意:给定一个$n(n\leqslant10^5)$序列,$m(m\leqslant10^5)$个询问,每个询问给出$l_1,r_1,l_2,r_2,l_3,r_3$.令$s$为该三个区间的交集的 ...
- 【bzoj2743】[HEOI2012]采花 树状数组
题目描述 萧芸斓是Z国的公主,平时的一大爱好是采花. 今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花.花园足够大,容纳了n朵花,花有c种颜色(用整数1-c表示),且花是排成一排的,以便于公 ...