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 |
|
Jonny1409
Posting Yak Master
133 Posts |
Posted - 2008-07-14 : 10:03:02
|
| Hello,I have a field in my DB which is a datetime, so it has entries in there like :13/08/2008 11:21:2618/12/2008 09:46:11etcI am trying to query based on this field, to only get the entries on a particular date but it is not coming up with anything.Obviously If I put the time in, it brings me them up, but this is no good as I don't want it specific to the second.What syntax would I use to get round this please ? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-14 : 10:08:05
|
| [code]where datecol>=dateadd(day,datediff(day,0,your_date),0) and datecol<dateadd(day,datediff(day,0,your_date),1) [/code]MadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-14 : 10:08:25
|
[code]declare @date datetimeselect @date = '2008-08-13'select *from yourtablewhere datecol >= @dateand datecol < dateadd(day, 1, @date)[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-07-14 : 10:10:36
|
| try select *from yourtablewhere afield >= particulardate and afield < DATEADD(day,1,particulardate)Jim |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-07-14 : 10:11:56
|
I knew I should have refreshed my browser before I posted, get the yak blaster! Jim |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-14 : 10:13:26
|
quote: Originally posted by jimf I knew I should have refreshed my browser before I posted, get the yak blaster! Jim
I also missed by few secs  KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Jonny1409
Posting Yak Master
133 Posts |
Posted - 2008-07-14 : 10:14:47
|
| Thanks very much - I appreciate it. |
 |
|
|
|
|
|
|
|