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 |
|
satheesh
Posting Yak Master
152 Posts |
Posted - 2012-09-11 : 09:42:58
|
| Dear All,I try to retrieve data based on date condition (last year currentdate + 24 day).when i use date function i am getting wrong result.startdate = DATEADD(year,-1,dateadd(day,24,dateadd(day,datediff(day,0,getdate()),0))) - result 86rowsif i use this -> (policy.StartDate between '2011-10-05 00:00:00.000' AND '2011-10-05 23:59:59.997') - result 137 rowswhat i am doing wrong in date function and how to change this.(i am getting different result when using function)Any help will be highly appreciated!ThanksRegards,SG |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2012-09-11 : 09:56:54
|
| Your first query returns values where stardate = '2011-10-05 00:00:00.000',exactly. The second returns anything that happened on 10/5startdate >=DATEADD(DAY,datediff(day,'19010101',CURRENT_TIMESTAMP),23)and startdate <DATEADD(DAY,datediff(day,'19010101',CURRENT_TIMESTAMP),24)JimEveryday I learn something that somebody else already knew |
 |
|
|
satheesh
Posting Yak Master
152 Posts |
Posted - 2012-09-11 : 10:37:45
|
| Thanks Jimf.Its working perfectly!! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|
|
|