| Author |
Topic |
|
kallileo
Starting Member
21 Posts |
Posted - 2007-10-16 : 15:55:40
|
| Can anybody explain to me why I get nothing when I execute: SELECT *FROM dataWHERE (timestamp >= 18 / 08 / 2007) AND (timestamp <= 21 / 08 / 2007)timesamp19/8/2007 10:25:59 am21/8/2007 10:25:27 am21/8/2007 10:46:11 am21/8/2007 10:46:21 pm23/8/2007 11:56:22 pm23/8/2007 12:22:46 am23/8/2007 12:23:17 am24/8/2007 12:32:19 pmdata is the table and timestamp the datetime column |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2007-10-16 : 16:13:57
|
| [code]Select *Into #TmpDatesFrom(select convert(datetime,'19/8/2007 10:25:59 am',103) as [TimeStamp]Union Allselect convert(datetime,'21/8/2007 10:25:27 am',103)Union Allselect convert(datetime,'21/8/2007 10:46:11 am',103)Union Allselect convert(datetime,'21/8/2007 10:46:21 pm',103)Union Allselect convert(datetime,'23/8/2007 11:56:22 pm',103)Union Allselect convert(datetime,'23/8/2007 12:22:46 am',103)Union Allselect convert(datetime,'23/8/2007 12:23:17 am',103)Union Allselect convert(datetime,'24/8/2007 12:32:19 pm',103)) aSelect * from #tmpDateswhere [TimeStamp] between Convert(Datetime,'18/08/2007',103) and Convert(Datetime,'22/08/2007',103)[/code] |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-10-16 : 16:17:28
|
You need to encapsulate your dates in single-quotes (and you should use YYYYMMDD format):SELECT *FROM dataWHERE (timestamp >= '2007-08-18') AND (timestamp <= '2007-08-21') As an example, try this and see what the results are:SELECT 18 / 08 / 2007, CAST(18 / 08 / 2007 AS DATETIME) |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-10-16 : 16:18:56
|
You need to put quotes around your string dates, and you should use 'YYYYMMDD' format so that they are server-locale-independent and un-ambiguous.A date of 18 / 08 / 2007(with no quotes) is a numeric division! (which will give an answer of Zero Krsiten |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-17 : 02:32:08
|
quote: Originally posted by Kristen You need to put quotes around your string dates, and you should use 'YYYYMMDD' format so that they are server-locale-independent and un-ambiguous.A date of 18 / 08 / 2007(with no quotes) is a numeric division! (which will give an answer of Zero Krsiten
Thats one disadvantages of implitcit conversionsI expect it to return error if dates are not sorrounded by single quotesMadhivananFailing to plan is Planning to fail |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-10-17 : 02:36:02
|
"I expect it to return error if dates are not sorrounded by single quotes"Well I'm with you on that one ... although I can see myself doing:SET @MyDate = (2007-1900) * 365 + (2007-1900) / 4 + 10 * 30 + 10 / 2 + 17)for an approximate date (actually it gives 19-November ...)Kristen |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-17 : 03:13:06
|
quote: Originally posted by Kristen "I expect it to return error if dates are not sorrounded by single quotes"Well I'm with you on that one ... although I can see myself doing:SET @MyDate = (2007-1900) * 365 + (2007-1900) / 4 + 10 * 30 + 10 / 2 + 17)for an approximate date (actually it gives 19-November...Error)Kristen
MadhivananFailing to plan is Planning to fail |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-10-17 : 03:47:52
|
Yeah, well I did a select convert(datetime, (2007-1900) * 365 + (2007-1900) / 4 + 10 * 30 + 10 / 2 + 17)to test it and assume with would work with a SET.That "assume" thing never works Kristen |
 |
|
|
kallileo
Starting Member
21 Posts |
Posted - 2007-10-17 : 11:50:21
|
| Thank you guys |
 |
|
|
|