In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you mysql to achieve time to datetime method, I hope you will learn a lot after reading this article, let's discuss it together!
Mysql implements the method of converting time to datetime: use [FROM_UNIXTIME (time value)] in the sql statement, and the code is [insert into test (time) values (FROM_UNIXTIME (% d)) ", time (NULL)].
The method of converting time to datetime by mysql:
FROM_UNIXTIME (time (NULL)) converts the time_t type time of the liunx system to the datetime type time of mysql:
Use FROM_UNIXTIME (time value) in sql statements
Convert the time value, time_t type to the datetime type of mysql.
Create table test (id int (11) auto_increment primary key,time datetime not null); char sqlbuf [4096]; snprintf (sqlbuf,sizeof [sqlbuf], "insert into test (time) values (FROM_UNIXTIME (% d))", time (NULL)); / / used in this way
UNIX_TIMESTAMP (field name of datatime type) converts the datetime type of mysql to time_t type::
Use UNIX_TIMESTAMP (the field name of a field of type datatime) in sql data
Convert the value of type datetime to type time_t
Char sqlbuf [4096]
Snprintf (sqlbuf,sizeof (sqlbuf), "select UNIX_TIMESTAMP (time) valuetime from test"); / / you can take out the value of type datetime and rename the field to valuetime.
+ create table user (id int unsigned not null primary key auto_increment, username char (40) not NULL, normterm char default NULL, smdtime datetime default NULL); insert into user values (1, 'Jone', NULL, NULL); after reading this article, I believe you have some understanding of mysql's method of converting time to datetime. Want to know more about it. Welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.