我的数据库是MySQL,如何数据库中时间字段是publictime,是datatime类型,如何查询20081010 00:00:00到20081011 00:00:00之间的信息,麻烦说的详细点。

解决方案 »

  1.   

    select form Table where publictime>'20081010 00:00:00' And  publictime<'20081011 00:00:00'select   *   from   date_time   where   starttime>='2006-6-20   00:00:00'   and   startti  
      me<='2006-7-01   23:59:59';   
      

  2.   

    select * from table where publictime between "20081010 00:00:00" and "20081011 00:00:00"
      

  3.   

    select * from table where publictime between "20081010 00:00:00" and "20081011 00:00:00"
      

  4.   

    怕自己写时间日期常量格式写错那就用 java.sql.PreparedStatement.setTimestamp 方法吧,相应 SQL 改为:
    SELECT * FROM your_table WHERE publictime BETWEEN ? AND ?
      

  5.   

    喜欢
    >= ? <= ?
    更灵活,从来不用BETWEEN 
    经测试海量数据 sqlserver库
    用between慢
    因为between要比较两次。
    是&的意思
    而非between是&&的意思
      

  6.   

    在mysql中,最好把时间保存为LONG类型的长整型数字,比较的时候直接比较大小,在程序中转换成需要的格式。
      

  7.   

    同意ls,时间getTime()后保存成long型入库比较好,便于日后比较排序等操作
      

  8.   


    select * from table where publictime between (开始时间) and (结束时间)