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)
 date difference

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-02-11 : 02:42:14
how can i select all records from my table where
date2 is more then 2 days from date1

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-11 : 02:50:25
[code]
select *
from mytable
where datediff(day, date1, date2) > 2

select *
from mytable
where date1 < dateadd(day, -2, date2)
[/code]


KH

Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-02-11 : 03:04:40
thanks.. now to make this more confusing

how can i do where the difference between
mydate from mytable1 is more then 2 days then select mydate1 from table2 where pid=id
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-11 : 03:35:47
select t1.*
from table1 as t1
inner join table2 as t2 on t1.id = t2.pid
where t1.date <= t2.date - 2


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -