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 2000 Forums
 Transact-SQL (2000)
 DateDiff

Author  Topic 

chipembele
Posting Yak Master

106 Posts

Posted - 2009-06-22 : 03:07:07
Hi
I need to calculate the number of days and weeks between two dates. The two dates are startdate and enddate columns.

Can anyone advise on the syntax please? The examples I have seen are for putting the actual dates in or calculating from the system date.

Thankyou

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-22 : 03:09:02
days => datediff(day, startdate, enddate)
weeks => datediff(week, startdate, enddate)


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

Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-06-22 : 03:10:38
see datediff details in bol
ex:-
declare @start datetime, @end datetime
select @start = '6/2/2009',
@end = '6/22/2009'
select datediff(d,@start,@end)
select datediff(wk,@start,@end)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-22 : 03:11:47
also refer to http://www.sqlteam.com/article/datediff-function-demystified


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

Go to Top of Page

chipembele
Posting Yak Master

106 Posts

Posted - 2009-06-22 : 03:31:36
Thanks for your help.
Go to Top of Page
   

- Advertisement -