Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 comparing date

Author  Topic 

codrgiii
Starting Member

29 Posts

Posted - 2010-10-20 : 12:46:20
how is it possible in sql 2005 to compare a date? i am using the GetDate() sql function to get the date, how is it possible to compare that result to something like

select @date = date from table

if @date > @2months
BEGIN
DO SOMETHING HERE
END


I want to compare the date from a table with 2 months, how is this possible?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-20 : 12:49:14
whats the datatype of @2months? if both are datetime this should work fine

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

codrgiii
Starting Member

29 Posts

Posted - 2010-10-21 : 01:03:26
they are smalldatetime, how would i be able to compare them? how would i gather the info that shows it to be @2months? would you show an example of this?
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-10-21 : 01:25:39
What value do you have in the variable @2months?

PBUH

Go to Top of Page

codrgiii
Starting Member

29 Posts

Posted - 2010-10-21 : 02:06:48
No var, i am unsure how to compare a date from a table with 2 months hence this topic. What i'm asking is how to compare @date (@date being smalldatetime data from a table) with 2 months later on from that date (@date), how would that be done?
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-10-21 : 02:54:24
Sample data.It will return current date & date after 2 months.



declare @date as datetime=getdate()
declare @2date as datetime=dateadd(mm,2,getdate())
select @date,@2date



PBUH

Go to Top of Page
   

- Advertisement -