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
 Development Tools
 ASP.NET
 date compare

Author  Topic 

teedah1
Starting Member

10 Posts

Posted - 2007-10-01 : 17:46:43
Hi! how to calculate date 2 and date 1, and display days elpased days betwn these dates. This is in MS SQL. thanks!!!!

Kristen
Test

22859 Posts

Posted - 2007-10-01 : 17:48:50
DATEDIFF(Day, EarlierDateColumn, LaterDateColumn)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-03 : 02:36:21
or in .NET, you can do date1-date1 or you can use datediff function available there

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

teedah1
Starting Member

10 Posts

Posted - 2007-10-08 : 14:49:33
thanks. now the problem is i want to display only days that are elapsed more than 2 day to show up.
if i use the datediff(day, ealierdate, laterdate) AS dayslapsed
how to sort the dayslapsed, since this is not really a column?
i can't do select *, datediff(day, ealierdate, laterdate) AS dayslapsed
from mytable
where dayslapsed > 2


Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-10-08 : 15:04:49
select *, datediff(day, ealierdate, laterdate) AS dayslapsed
from mytable
where datediff(day, ealierdate, laterdate) > 2

Kristen
Go to Top of Page
   

- Advertisement -