| Author |
Topic |
|
mapidea
Posting Yak Master
124 Posts |
Posted - 2009-02-03 : 04:04:55
|
| I want to get all the orders placed in month of december between 12 Noon and 5 pm.I got the december part. How can we get the time section.select * from orderswhere (orderdate between '2008/12/12' and '2008/12/31')and "What will be syntax to get time?"Thanks |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2009-02-03 : 04:07:24
|
| look up the DATEPART function in books onlineEm |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-02-03 : 04:14:59
|
| select * from orderswhere orderdate between convert(varchar(32),datefield,100) and convert(varchar(32),datefield,100) |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-03 : 04:16:46
|
| try like this using datepart as elancaster saidselect * from orderswhere (orderdate between '2008/12/12' and '2008/12/31')and datepart(h,orderdate) > 12 and datepart(hh,orderdate)<17 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-03 : 09:21:21
|
quote: Originally posted by Nageswar9 select * from orderswhere orderdate between convert(varchar(32),datefield,100) and convert(varchar(32),datefield,100)
this might not work as expected as between will consider dates as strings rather than date values themselves |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-03 : 09:22:24
|
quote: Originally posted by bklr try like this using datepart as elancaster saidselect * from orderswhere (orderdate between '2008/12/12' and '2008/12/31')and datepart(h,orderdate) > 12 and datepart(hh,orderdate)<17
this wont return any records between the dates which has a time part outside this range (12-17) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-03 : 09:23:37
|
| [code]select * from orderswhere orderdate >= '2008/12/12 12:00' and orderdate <='2008/12/31 17:00'[/code] |
 |
|
|
mapidea
Posting Yak Master
124 Posts |
Posted - 2009-02-03 : 09:23:57
|
| visakh16 the query you gave will return all the order between that date.I am looking for orders in the particular time slot on all those days. Given by bklr.Thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-03 : 09:40:12
|
quote: Originally posted by mapidea visakh16 the query you gave will return all the order between that date.I am looking for orders in the particular time slot on all those days. Given by bklr.Thanks
Oh ok...i thought you're looking for time range.In that case the previous suggestion should work fine. |
 |
|
|
mapidea
Posting Yak Master
124 Posts |
Posted - 2009-02-03 : 09:47:01
|
| Yes. Thanks |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-03 : 23:15:43
|
| hi visakh, for only timepart given query will works fine i have checked the query by sample data |
 |
|
|
|