您好,欢迎访问一九零五行业门户网

mysql时间问题_MySQL

1. mysql中提供的日期和时间:
mysql> desc test_time;+--------+---------------------+------+-----+-------------------+-----------------------------+| field | type | null | key | default | extra |+--------+---------------------+------+-----+-------------------+-----------------------------+| id | bigint(20) unsigned | no | pri | null | auto_increment || t_date | date | yes | | null | || t_time | time | yes | | null | || t_ts | timestamp | no | | current_timestamp | on update current_timestamp || t_dt | datetime | yes | | null | |+--------+---------------------+------+-----+-------------------+-----------------------------+5 rows in set (0.00 sec)mysql> insert into test_time(t_date,t_time,t_dt) values(curdate(),curtime(), now());query ok, 1 row affected (0.00 sec)mysql> select * from test_time;+----+------------+----------+---------------------+---------------------+| id | t_date | t_time | t_ts | t_dt |+----+------------+----------+---------------------+---------------------+| 1 | 2014-06-19 | 15:53:39 | 2014-06-19 15:53:39 | 2014-06-19 15:53:39 || 2 | 2014-06-19 | 15:53:57 | 2014-06-19 15:53:57 | 2014-06-19 15:53:57 || 3 | 2014-06-19 | 15:54:01 | 2014-06-19 15:54:01 | 2014-06-19 15:54:01 || 4 | 2014-06-19 | 15:54:38 | 2014-06-19 15:54:38 | 2014-06-19 15:54:38 |+----+------------+----------+---------------------+---------------------+4 rows in set (0.00 sec)
2. 当修改表中数据时,t_ts自动更新为当前时间:
mysql> update test_time set age=4 where id=4;query ok, 1 row affected (0.00 sec)rows matched: 1 changed: 1 warnings: 0mysql> mysql> select * from test_time;+----+------------+----------+---------------------+---------------------+-----+| id | t_date | t_time | t_ts | t_dt | age |+----+------------+----------+---------------------+---------------------+-----+| 1 | 2014-06-19 | 15:53:39 | 2014-06-19 15:59:32 | 2014-06-19 15:53:39 | 1 || 2 | 2014-06-19 | 15:53:57 | 2014-06-19 15:59:41 | 2014-06-19 15:53:57 | 2 || 3 | 2014-06-19 | 15:54:01 | 2014-06-19 15:59:49 | 2014-06-19 15:54:01 | 3 || 4 | 2014-06-19 | 15:54:38 | 2014-06-19 15:59:55 | 2014-06-19 15:54:38 | 4 |+----+------------+----------+---------------------+---------------------+-----+
3. 时间比较:
mysql> select * from test_time where to_days(now()) - to_days(t_date)
select * from test_time where unix_timestamp(t_ts) >= unix_timestamp() -1800 and unix_timestamp(t_ts)
4. mysql设计friendfeed
  http://backchannel.org/blog/friendfeed-schemaless-mysql

其它类似信息

推荐信息