少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks
          在MYSQL中插入當(dāng)前時(shí)間:

            NOW()函數(shù)以`'YYYY-MM-DD HH:MM:SS'返回當(dāng)前的日期時(shí)間,可以直接存到DATETIME字段中。
            CURDATE()以’YYYY-MM-DD’的格式返回今天的日期,可以直接存到DATE字段中。

            CURTIME()以’HH:MM:SS’的格式返回當(dāng)前的時(shí)間,可以直接存到TIME字段中。
            例:insert into tablename (fieldname) values (now())

            now():以'yyyy-mm-dd hh:mm:ss'返回當(dāng)前的日期時(shí)間,可以直接存到datetime字段中。
            curdate():’yyyy-mm-dd’的格式返回今天的日期,可以直接存到date字段中。

             

          //獲取Mysql系統(tǒng)時(shí)間   
          select now() as systime  ; 
          select sysdate() as systime  ; 
          select current_date as systime ;
          select current_time as systime ;
          select current_timestamp as systime ;
          select * from abing where to_days(sysdate())=to_days(createtime);   
          select * from abing where to_days(sysdate())=to_days(createtime);   
           select * from abing where str_to_date(now(),'%Y-%m-%d')=str_to_date(createtime,'%Y-%m-%d');  
          自己寫的例子,為了以后忘記了查詢用:
          use abin;
          create table abin1(
          id integer not null auto_increment,
          name varchar(100),
          create_time datetime ,
          update_time datetime ,
          constraint pk_abin1 primary key(id));
          insert into abin1(name,create_time,update_time) values ('abin1',now(),now());
          insert into abin1(name,create_time,update_time) values ('abin1',sysdate(),sysdate());




          posted on 2012-12-14 14:32 abin 閱讀(479) 評(píng)論(0)  編輯  收藏 所屬分類: mysql
          主站蜘蛛池模板: 焦作市| 保亭| 平乐县| 孟州市| 进贤县| 青河县| 揭西县| 南丰县| 随州市| 蒙山县| 墨脱县| 岗巴县| 克拉玛依市| 南皮县| 鄂伦春自治旗| 平顶山市| 怀化市| 万宁市| 西充县| 贺州市| 常宁市| 华容县| 临沂市| 永济市| 塘沽区| 高台县| 虞城县| 阿拉尔市| 绵阳市| 扬州市| 金阳县| 昆山市| 金堂县| 中阳县| 巴东县| 长寿区| 云林县| 宁晋县| 开鲁县| 稷山县| 祁门县|