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.
| Author |
Topic |
|
amgrace
Starting Member
30 Posts |
Posted - 2004-08-10 : 13:03:47
|
| Hi,I am trying to write a query to retrieve info from a table, but a I want to add a calculated field to my result i.e The table has a STARTDATE and ENDDATE for each record and I want to know the number of days between those date (Which will be displayed as field "LenghtOfStay". Can you please help.If field StartDate = 1/1/2004 and field EndDate = 5/1/2004Then my LengthOfStay field shold display "4" for that record.ThanksGrace |
|
|
drymchaser
Aged Yak Warrior
552 Posts |
Posted - 2004-08-10 : 13:09:12
|
| DATEDIFF(dd, StartDate, EndDate)StartDate and EndDate need to be dates OR character data that can be implicitly transformed to a date.Your dates seem to be dd/mm/yyyy so your server DATEFORMAT setting would need to be DMY.How do the dates get passed to the query? |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-08-10 : 13:09:52
|
| select datediff(d, '1/1/2004', '1/5/2004')select datediff(d, StartDate, EndDate)Go with the flow & have fun! Else fight the flow :) |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-08-10 : 13:10:39
|
| where is that picure of a yak getting shot in the head? :)))))Go with the flow & have fun! Else fight the flow :) |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-08-10 : 13:27:37
|
MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-08-10 : 13:34:04
|
| yeah how do you get that??Go with the flow & have fun! Else fight the flow :) |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-08-10 : 13:35:58
|
| [s n i p e d]Take out the spaces.MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-08-10 : 13:36:52
|
-- great it works. thanx derrickGo with the flow & have fun! Else fight the flow :) |
 |
|
|
amgrace
Starting Member
30 Posts |
Posted - 2004-08-11 : 06:40:16
|
| Thanks very much guys.....great help. |
 |
|
|
|
|
|