Expiry Date = '2017-10-16' and ExpiryTime='12:00pm' in table and in our country Getdate is '2017-10-16' and currentdatetime is '2017-10-16 11:05:33.503'
but still, my code executes the IF condition which it should not. Why ?
Declare @ExpiryDate date
Declare @ExpiryTime varchar(10)
Set @ExpiryDate= (Select convert(varchar(11), ExpiryDate, 106) from Works where NIT_No= @NITNo and WorkNo= @WorkNo)
Set @ExpiryTime= (Select CAST(ExpiryTime as TIME(0)) from Works where NIT_No= @NITNo and WorkNo= @WorkNo)
IF(CONVERT(DATETIME,CONVERT(VARCHAR,@ExpiryDate,106)+ ' ' + @ExpiryTime) <= CONVERT(datetime, GETDATE()))
Begin
RAISERROR('Sorry, Expiry date and time has passed', 16, 10);
return;
End
106and also why are doing so many conversions between varchar and date?12:00pm...I can't tell if that's 2017-10-16 morning (0:00) or 2017-10-17 0:00...in the first case, yourIFistrue.