Date Diff.. | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Date Diff..


Is there any function which gives the date difference for no of dates as datediff() gives the difference between only two specific dates. Regards,
Hema Sunder.
Can you give an example? I’m not sure I understand you. —
Frank Kalis
Moderator
Microsoft SQL Server MVP
Webmaster:http://www.insidesql.de

Let me explain in detail: DATEDIFF ( datepart , startdate , enddate ) gives difference between only two specific dates. I have multiple startdates and end dates and want the difference between those dates. Regards,
Sunder.
Do you mean you have a table with one startdate and one enddate and now want to have the DATEDIFF for each row? Or do you have multiple startdate and enddate columns in your table?<br /><br />Sorry, but I define "detailed" a bit different than you. [<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]<br /><br />–<br />Frank Kalis<br />Moderator<br />Microsoft SQL Server MVP<br />Webmaster:<a target="_blank" href=http://www.insidesql.de>http://www.insidesql.de</a>

I want datediff for multiple records at a time.
It is not very clear on what you want. Please post your table DDL, some sample data and the result that you want
KH
Why not use a correlated subquery like this: SELECT t1.mydate,
DATEDIFF(day, (SELECT MAX(t2.mydate) FROM tbl t2 WHERE t2.mydate < t1.mydate), t1.mydate)
FROM tbl t1
ORDER BY t1.mydate
quote:Originally posted by bugatha
I want datediff for multiple records at a time.
Dont Let everyone guess what you want
As Tan said, post some sample data and the result you want Madhivanan Failing to plan is Planning to fail
The query I posted gives him the DateDiff between the current row and the previous row, when sorted by the date column.
]]>