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 |
|
spock
Starting Member
35 Posts |
Posted - 2002-01-06 : 02:22:28
|
| Hi,when i run the query below select datediff( dd, cast(1-1-2002 as datetime) , getdate() )i get the result as39262 2002-01-06 07:11:18.263why am i not getting 5 as the difference?thankskaushikEdited by - spock on 01/06/2002 02:34:04Edited by - spock on 01/06/2002 02:34:40 |
|
|
aclarke
Posting Yak Master
133 Posts |
Posted - 2002-01-06 : 02:39:33
|
select datediff( dd, cast('1-1-2002' as datetime) , getdate() )Notice the apostrophes. I'll leave it to you to figure out how this changes the meaning of your code. |
 |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-01-06 : 02:39:45
|
| You need to put the datatime value in quotes , otherwise it will be treated as a number and an equivalent datetime is converted.for cast(1-1-2002 as datetime)the date it gives is '1894-07-09 00:00:00.000'for cast('1-1-2002' as datetime) will give you 1-1-2002 only.Remember internally Dates are stored as numbers.Therefore , your query should beselect datediff( dd, cast('1-1-2002' as datetime) , getdate() ) this will give you 5HTH----------------------------Anything that Doesn't Kills you Makes you Stronger |
 |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-01-06 : 02:41:53
|
Beaten by 12 Secs Clarke , Am sorry didnt kept anything to figure out , ofcourse if am right there----------------------------Anything that Doesn't Kills you Makes you StrongerEdited by - Nazim on 01/06/2002 02:42:41 |
 |
|
|
|
|
|