Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Saving date and time and getting date
Message
 
 
To
24/02/2010 05:55:41
Metin Emre
Ozcom Bilgisayar Ltd.
Istanbul, Turkey
General information
Forum:
Microsoft SQL Server
Category:
Database design
Miscellaneous
Thread ID:
01450712
Message ID:
01450749
Views:
48
>Hi All,
>
>I will create a datetime field. I'll save date and time to it. I need date and time and have filtering just date part. Should I create an index like;
>
>CONVERT(char(10),mydate,112)
>
>and use;
>vfp:
>xmydate=dtoc(date(),1)
>sql server:
>where convert(char(10),mydate,112)=?xmydate
>
>for performance
>
>or is just an index with mydate is enough for performance;
>
>vfp:
>xmydate=date()
>sql server:
>where mydate=?xmydate

Metin,

In SQL Server you can not create an index using a function. Use a date range when looking for a date, e.g.
select * from myTable where DateField >=@Today and DateField < @Tomorrow
See these links for working with dates:

The ultimate guide to the datetime datatypes

http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/16/bad-habits-to-kick-mishandling-date-range-queries.aspx

and also

http://wiki.lessthandot.com/index.php/Date_Range_WHERE_Clause_Simplification
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform