Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Any problems using char(8) for dates in YYYMMDD
Message
From
29/12/2001 12:58:30
 
General information
Forum:
Microsoft SQL Server
Category:
Database design
Miscellaneous
Thread ID:
00598911
Message ID:
00599147
Views:
30
>We will need to create reports based on start and end dates. We do not need any minutes and seconds. I am thinking to create an extra column for dates in char(8) in the format YYYYMMDD to store dates and create an index to make the reports go faster instead of having a datetime column.
>
>Does anyone use the same idea?
>Any problems when using <>= for start and end dates?
>
>Thanks

You don't need to create an extra column and index, use the same datetime column and and just convert the column to a char in the returned set for the desired format. You can use CONVERT() for this like so:
Select CONVERT(Char(8), myDateField, 112) From myTable Where myDateField = '2001-12-29'
And use an index on the datetime column for help in optimizing. For start and end dates use BETWEEN instead. Something like:
Select CONVERT(Char(8), myDateField, 112) From myTable Where myDateField BETWEEN '2001-12-29' AND '2001-12-31'
Hope this helps.
Previous
Reply
Map
View

Click here to load this message in the networking platform