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)
 Round Down between Dates

Author  Topic 

JezLisle
Posting Yak Master

132 Posts

Posted - 2008-09-08 : 09:48:42
In Excel I use the RounDown function, I'm relatively new to SQL Server.

How would it be possible to workout the difference in dates between todays date and a date input into a database. The function I use in Excel is =ROUNDDOWN((today()-B1)/7,0)

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-09-08 : 09:50:17
What do you mean by "workout the difference in dates" ? Do you want to return the # of days between two dates?

Look at the DateDiff function in T-SQL, it should be able to do what you are looking for.

Also, see this: http://www.sqlteam.com/article/working-with-time-spans-and-durations-in-sql-server



- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

JezLisle
Posting Yak Master

132 Posts

Posted - 2008-09-08 : 10:01:24
I'm looking at the difference in days between to dates. Date1 is today and Date2 is a date entered by user.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-09-08 : 10:05:11
Great! Now read the rest of my post and follow the advice given.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

JezLisle
Posting Yak Master

132 Posts

Posted - 2008-09-09 : 04:50:48
I've had a read of your link you attached Jeff, Thanks...

I'm a little unsure on things still. Using the CAST()Function, I trying to workout the difference between the 2 days. I looked at the samething in Access and found that CInt(Date()-[Date on Waiting List])/7 AS [Weeks Waiting] worked how I wanted. How can I transfer this to SQL Server?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-09 : 05:00:50
Use

DATEDIFF(DAY,[Date on Waiting List]),GETDATE())/7


Madhivanan

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

JezLisle
Posting Yak Master

132 Posts

Posted - 2008-09-09 : 05:17:58
Thanks, It tells me that using DATEDIFF(DAY,[Date on Waiting List]),GETDATE())/7 That datediff function requires 3 argument(s)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-09 : 05:26:40
That should be

DATEDIFF(DAY,[Date on Waiting List],GETDATE())/7

Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-09 : 05:27:09
Remove the extra paranthesis

DATEDIFF ( DAY , [Date on Waiting List] , GETDATE() ) / 7



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

JezLisle
Posting Yak Master

132 Posts

Posted - 2008-09-09 : 05:32:18
Excellent Thanks :)
Go to Top of Page
   

- Advertisement -