How to insert a microsecond-precision datetime into mysql?

后端 未结 4 2115
野的像风
野的像风 2020-12-28 15:38

I have a string like this:

2011-11-11 11:11:11.111111

and I need to insert it in MySql, into a datetime column. But after I insert it, it b

4条回答
  •  太阳男子
    2020-12-28 16:00

    Some samples of inserting datetime values into MySQL(5.6.17)

    create database if not exists mydb;
    use mydb;
    drop table if exists sample;
    create table sample (c1 integer, c2 datetime(6),c3 varchar(30));
    insert into sample values (1, '2014-07-25 11:18:10.999999', 'Actual Given Value');
    insert into sample values (2, now(6), 'From NOW(6) function');
    insert into sample values (3, now(), 'From NOW() function');
    insert into sample values (4, sysdate(6), 'From sysdate(6) function');
    insert into sample values (5, sysdate(), 'From sysdate() function');
    
    select * from sample;
    
     # c1, c2, c3
    '1', '2014-07-25 11:18:10.999999', 'Actual Given Value'
    '2', '2014-07-25 11:27:27.314114', 'From NOW(6) function'
    '3', '2014-07-25 11:27:27.000000', 'From NOW() function'
    '4', '2014-07-25 11:27:27.429121', 'From sysdate(6) function'
    '5', '2014-07-25 11:27:27.000000', 'From sysdate() function'
    

提交回复
热议问题