DateTime aaa=DateTime.Parse("2002-02-02");
         DateTime bbb=DateTime.Parse("2002-08-08");
         int x=System.DateTime.Compare(aaa,bbb);
 如果x=-1 aaa<bbb
    x=0 aaa=bbb
    x=1 aaa>bbb

解决方案 »

  1.   

    补充:数据库为MS-SQL。谢谢楼上,但我是想直接写在SQL语句中,因为我还有其它项一起查询的。
      

  2.   

    先把日期取到2个字符串中btime和etime
    select * from table where date between cast(btime as signdate) and cast(etime as signdate
      

  3.   

    string strSql="select * from table where myDate>'2003-1-1'";
      

  4.   

    请问在SQL中时间类型有DateTime,SmallDateTime,我定义的是SmallDateTime,这样对SQL语句是否有影响?
      

  5.   

    你 用 DateTime类型。
    用查询分析器查询看看有没错误。
    我记得该没错的。
      

  6.   


    CREATE PROCEDURE upQueryTransInfoByDateTime
    (
        @TransDate1  datetime ,
        @TransDate2  datetime 
    )
    AS
     
       SELECT *  FROM TransInfo
         where convert(char(8),OrderDateTime,112)
                   >=convert(char(8),@TransDate1,112)
                    convert(char(8),OrderDateTime,112)
                  <=convert(char(8),@TransDate2,112)
      

  7.   

    --抄自SQL SERVER联机丛书Microsoft SQL Server 用两个 4 字节的整数内部存储 datetime 数据类型的值。第一个 4 字节存储 base date(即 1900 年 1 月 1 日)之前或之后的天数。基础日期是系统参考日期。不允许早于 1753 年 1 月 1 日的 datetime 值。另外一个 4 字节存储以午夜后毫秒数所代表的每天的时间。smalldatetime 数据类型存储日期和每天的时间,但精确度低于 datetime。SQL Server 将 smalldatetime 的值存储为两个 2 字节的整数。第一个 2 字节存储 1900 年 1 月 1 日后的天数。另外一个 2 字节存储午夜后的分钟数。日期范围从1900 年 1 月 1 日到 2079 年 6 月 6 日,精确到分钟。
      

  8.   

    try:SELECT * FROM table
    WHERE signdate BETWEEN CAST(Value1 AS SMALLDATETIME) AND 
                           CAST(Value2 AS SMALLDATETIME)
      

  9.   

    select * from table where date between date1 and date2
      

  10.   

    直接用大于、小于号进行比较要比用between..and好些!
      

  11.   

    string sqlString = "select * from table where signdate >= '" + tbFrom.Text + " ' and signdate =< '" + tbTo.Text + "'";
      

  12.   

    string sqlstring="select * from table where signdate between '" & tbform.text & _
                       "' and '" & tbto.text & "'"
      

  13.   

    前提是先判定tbform.text 和tbto.text的数据是日期格式的
      

  14.   

    我的同事已成功解决了这一问题:
    就是用日期字段和字符串比较,
    但是日期型的字符串必须是两位月和两位日:
    "2003-07-01",不过他用的是Access,
    不过我在pb中用sqlserver时用过:
    select ... from table where 日期字段 between ...and....
    是没问题的,and 的两边是日期型变量值.
      

  15.   

    SQL Server : > < >= <= <> '2001-01-02'
    Oracle : > < >= <= <> to_date('2001-01-02','yyyy-mm-dd')
    DB2 ...
      

  16.   

    dim sqlstr as string
    sqlstr="select * from table where date between '" & text1.text & "' and '"
      & text2.text & "'"