SyntaxDATEDIFF(datepart, startdate, enddate)ArgumentsdatepartIs the parameter that specifies on which part of the date to calculate the difference. The table lists dateparts and abbreviations recognized by Microsoft®
 SQL Server™.Datepart Abbreviations
year yy, yyyy
quarter qq, q
month mm, m
dayofyear dy, y
day dd, d
week wk, ww
hour hh
minute mi, n
second ss, s
millisecond ms

解决方案 »

  1.   

    select * from 表 where datetime between between getdate() and  getdate()+advancedtime
      

  2.   

    select * from 表 where between convert (datetime,convert (varchar(10),getdate(),120) )
    and  convert (datetime,convert (varchar(10),getdate()+advancedtime
    ,120) )
    比较准确
      

  3.   

    to solidpanther(我爱机器猫):
    谢谢,可是这样只可以求出在那段时间范围内的,而当天的求不出来啊
    如:datetime='2004/1/15' advancedtime=0
    当系统时间为'2004/1/15'时,应该可以求出上面这条记录
    但是用你的语句却求不出来
      

  4.   

    谢谢solidpanther(我爱机器猫),你的语句可以了,最后一个问题,成功就结帖了
    如果我的datetime不是时间型而是varchar型呢?
      

  5.   

    我试了试,varchar也是一样的效果
    结帖了~~~~~~~~~~~~~~~~~~
    接分吧~~~~~~~~~~~~~~~~~~~~~~~~~~~
    谢谢了~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~