Get Date and compare with Date.Now in T-SQL

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.


Best regards,

Ron.

0
ronnyr
6/2/2006 7:35:20 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

4 Replies
1100 Views

Similar Articles

[PageSpeed] 30
Get it on Google Play
Get it on Apple App Store

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)

0
samsta
6/2/2006 8:51:56 PM

Thanks samsta,

but I got an error when I am using Date.Now(). Then, I change with GetDate() function and works just fine now.

Thank you.


Best regards,

Ron.

0
ronnyr
6/3/2006 12:21:43 AM
Ahh I take it you are using SQL 2000 or SQL 2005 and not using .NET...?
0
samsta
6/3/2006 1:59:50 AM

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
Pune, India
http://www.firozansari.com
Why product testing is important?
0
firoz
6/3/2006 5:45:56 AM
Reply: