Home > Database > Mysql Tutorial > body text

Mysql那些事儿之(五)操作时间_MySQL

WBOY
Release: 2016-06-01 13:39:29
Original
1117 people have browsed it

bitsCN.com
Mysql那些事儿之(五)操作时间 一、时间       命令:SELECT CURDATE();      功能:以‘YYYY-MM-DD’的格式返回今天日期值。       命令:SELECT CURTIME();      功能:以‘HH:MM:SS’的格式返回时间。       命令:SELECT NOW();      功能:以‘YYYY-MM-DD HH:MM:SS’的格式返回时间。 二、自动记录时间          TIMESTAMP 列类型可以自动的标记 INSERT UPDATE的操作的时间。      举例:      创建表      CREATE TABLE student(      id INT,      english TINYINT,      math TINYINT,      chinese TINYINT,      time TIMESTAMP           );       插入数据:      INSERT INTO student(id,english,math,chinese) VALUES(1,12,23,45);       查询数据:      SELECT * FROM student;      结果:      ---------------------------------------------------------------------      id   |  english | math | chinese |             time                |      ---------------------------------------------------------------------        1  |  12        |  23    |    45      |  2012-10-20 10:34:09      ---------------------------------------------------------------------       time列自动加入了数据INSERT 的时间。UPDATE 同样会影响数据的time列的时间值。       TIMESTAMP 的存储需求是4个字节;DATETIME存储需求是8个字节。     三、比较时间       SELECT TO_DAYS(date);      给出一个日期date,返回从0年开始算的天数(到date为止)。       举例:      SELECT TO_DAYS(NOW())-TO_DAYS('2012-10-19'):      返回  1 天。      SELECT TO_DAYS(NOW());      返回  735161 天。即从现在到0年为止的天数。 bitsCN.com

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!