1.DATEDIFF() 函数返回两个日期之间的天数:具体格式为:DATEDIFF(datepart,startdate,enddate)
其中datepart和startdate是合法的日期格式,datepart可以是 年、月、日等等。
select * from student where DATEDIFF(day,'1992-02-18','1992-02-20' ) between 0 and 3
三天之内过生日的人的信息:
select * from Student
where DATEDIFF(day,GetDate(),Convert(varchar(5),DatePart(yyyy,GetDate()))+'-'+Convert(varchar(5),DATEPART(mm,BirthDay)) +'-'+Convert(varchar(5),DATEPART(dd,BirthDay)))
between 0 and 3
2.DATEPART() 函数用于返回日期/时间的单独部分,比如年、月、日、小时、分钟等等:具体格式为:DATAPART(datepart,date) (下面格式是在http://www.w3school.com.cn/sql/func_datepart.asp截的图)
select * from Student
where DATEDIFF(day,GetDate(),Convert(varchar(5),DatePart(yyyy,GetDate()))+'-'+Convert(varchar(5),DATEPART(mm,BirthDay)) +'-'+Convert(varchar(5),DATEPART(dd,BirthDay)))
between 0 and 3