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 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2005-07-20 : 05:32:41
|
Hi Everyone.I am using the between getting the dates, i m facing some problem with the same. CreatedDate 2005/07/192005/07/192005/07/20this is the sample date which there in the table.select * from TabName where CreatedDate Between '2005/07/18' And '2005/07/20'when i pass the query is gives following output CreatedDate2005/07/192005/07/19the record '2005/07/20' is not comming .. i Analysed the same, and found the problem is because of the time..i suppose.. then i passed the following query... which worked fine for me.. Select * From TabName Where Covert(Varchar,CreatedDate,111) Between Convert(Varchar,'2005/07/18' ,111) and Convert(Varchar,'2005/07/20' 111)this returned me all the records.. i want to know is this only solution are there is some other way to do it.. ? and would like to know is this because of time thing are something other... thanksComplicated things can be done by simple thinking |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-07-20 : 06:24:26
|
you can get rid of the time portion with this:SELECT GetDate(), DATEADD(d, DATEDIFF(d, 0, GetDate()), 0)Select * From TabName Where CreatedDate Between DATEADD(d, DATEDIFF(d, 0, '2005/07/18'), 0)and DATEADD(d, DATEDIFF(d, 0, '2005/07/20')+1, 0) -- notice the +1 day. that gives all dates on 20th.Go with the flow & have fun! Else fight the flow |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-07-20 : 06:52:29
|
It is bacause the date has time portion and you write a query without including thatSo you have to use what spirit1 specified or simply asselect * from TabName where CreatedDate >='2005/07/18' And CreatedDate < DateAdd(d,1,'2005/07/20') MadhivananFailing to plan is Planning to fail |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2005-07-20 : 07:45:56
|
Thanks a lot... Complicated things can be done by simple thinking |
 |
|
|
|
|
|
|
|