Handling date in SQL Server

后端 未结 2 2002
面向向阳花
面向向阳花 2020-12-12 06:54

I am working on a website in asp.net. I am getting a date from a web page and then depending on the user input I want to get results from SQL Server database (using stored p

2条回答
  •  旧时难觅i
    2020-12-12 07:20

    If you only want compare with day level and ignoring the hours part, you can use DateDiff function. Pass d or DAY to interval parameter of DateDiff

    For example:

    DECLARE @sDate VARCHAR(100)='2016-10-08'
    IF ISDATE(@sDate)=1
    BEGIN
       select * 
       from table 
       where datediff(d,acceptedDate,@sDate)=0  --same day
    END
    ELSE 
     PRINT 'Invalid date format!'
    

提交回复
热议问题