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)
 difference between 2 dates

Author  Topic 

rohit04413
Yak Posting Veteran

72 Posts

Posted - 2010-05-05 : 01:24:30
hello all !!!

i have a table with 2 columns DateIn and DateOut.
i want to have a 3rd column which automatically calculate difference between datein and dateout as number of days.

how can i do that? may i use the computed column specification property of the 3rd column.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-05-05 : 01:36:04
yes.


alter table <table name> add
DiffDays as datediff(day, DateIn, DateOut)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-05 : 02:26:48
do you mean absolute days thats passed or number of equivalent days based on elapsed hours?

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

Go to Top of Page

rohit04413
Yak Posting Veteran

72 Posts

Posted - 2010-05-05 : 02:40:24
quote:
Originally posted by khtan

yes.


alter table <table name> add
DiffDays as datediff(day, DateIn, DateOut)



KH
[spoiler]Time is always against us[/spoiler]




ThankYou.
i just put datediff(day, DateIn, DateOut) into computed column specification and it worked out.
Go to Top of Page
   

- Advertisement -