Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Server DateTime in SQL Select
Message
From
10/05/2010 10:23:09
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01463837
Message ID:
01463942
Views:
50
This is original message quoted:

What is the right syntax for BETWEEN with two DateTime values (in SQL Select called from VFP app)? I am using the following syntax and getting an error:
TableName.FieldName between {^2010-04-01 00:00:00} and {^2010-05-01 00:00:00}
And this is quoted from the blog lines you provided:

SELECT COUNT(*)
FROM dbo.SomeLogTable
WHERE DateColumn BETWEEN '20091011' AND '20091012';
Well, this approach is okay, as long as you don't have any rows that fall on midnight at the upper bound - which can be much more common if parts of your application strip time from date/time values. In that case, this query will include data from the next day; not exactly what was intended. In some cases, that *is* what is intended: some people think the above query should return all the rows from October 11th, and also all the rows from October 12th. Remember that this query can be translated to one of the following, without changing the meaning:
SELECT COUNT(*)
FROM dbo.SomeLogTable
WHERE DateColumn BETWEEN '2009-10-11T00:00:00.000' AND '2009-10-12T00:00:00.000';
-- or
SELECT COUNT(*)
      FROM dbo.SomeLogTable
      WHERE DateColumn >= '2009-10-11T00:00:00.000' AND DateColumn <= '2009-10-12T00:00:00.000';
(Note that in the second example, that is greater than or equal to the first variable and less than or equal to the second variable.) This means that you will return rows from October 12th at exactly midnight, but not at 1:00 AM, or 4:00 PM, or 11:59 PM.

***********************************************
So I would say Thanks, period.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform