Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select by Date from DateTime in SQL Server
Message
From
11/08/2017 15:48:34
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01653212
Message ID:
01653248
Views:
61
>>>Hi,
>>>
>>>I am working with the SQL Server database. The field/column is DateTime. And I want to get records by the following criteria:
>>>
>>>
>>>select * from MyTable where DateTimeCol <= '20170810'  
>>>
>>>
>>>Since the DateTimeCol has both the date and time, the above will select 0 records.
>>>
>>>How should I change the WHERE to make sure that only the Date of DateTime is considered and therefore the records where the Date is '20170810' are returned?
>>
>>Simply:
>>
>>
>>select * from MyTable where DateTimeCol < '20170811'  
>>
>
>Thank you, Cetin. It is just that my existing code already uses the Less Than or Equal (not Less Than) and the approach suggested by Martina (cast DateTimeCol as date) works perfectly.


From my POV, changing code from LTE to LT is easier than converting it to use a cast() statement and it is portable, version independent, doesn't have the unneccassry conversion overhead etc. Anyway it is your code.
Ç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
Reply
Map
View

Click here to load this message in the networking platform