I am trying to set an alert to user for a project which will due on the particular date.
How to compare the DateTime due date which I get from the database with the Date.Now in stored procedure?
Thanks in advance.
Make sure they are both in the same format. Many different ways to accomplish.
The example below would convert both to a date:
select * from table where convert(nvarchar(15),DueDate,101) = convert(nvarchar(15),Date.Now(),101)
but I got an error when I am using Date.Now(). Then, I change with GetDate() function and works just fine now.
Ahh I take it you are using SQL 2000 or SQL 2005 and not using .NET...?
Here is the SQL code snippet: First exmaple will return date difference between assign date and current server date. Using same logic, second exmaple will return all tasks which has exceed thier due date.
declare @dueDate as datetime
set @dueDate = '05/25/2006'
print datediff(day, @dueDate, getdate())
select * from tasks where datediff(day, @dueDate, getdate())>1
I hope you will get some pointer.
~ Firoz Ansari
Why product testing is important?