Register
Sunday, February 05, 2012
 
 DBAs And ProgrammersBlog
  
News! Minimize
   
 
 Print   
 
Misc Blog Stuff Minimize
   
 
 Print   
 
The Reluctant DBA Minimize
 
 
 
 Print   
 
Reluctant DBA Minimize
   
 
  
 
Reluctant DBA Minimize
   
 
  
 
The Reluctant DBA Minimize
 
Oct22

Written by:CarpDeus
10/22/2008 9:43 AM 

 I'm working on all of the sample code for my presentation at VSLive, "Implementing Caching Technology as One Rung of the Scalability Ladder" and I'm updating the samples that I used for my memcached book. That used a web based calendar of events which I'm sticking to but updating to SQL 2008.

And one of the nice things about SQL 2008 is that it has a date data type. Which is a really big, even though it is minor, thing. For the history of SQL Server, we've had datetime and smalldatetime which gave you some precision over what was stored but, if you wanted to just track a date, like 12/14/2008, you had to store it as one of those two data types, which always meant that it appeared as '2008-12-24 00:00:00.000', which doesn't look bad but you could never definitively tell if that was a date only or just happened to be midnight. 

Conversely, SQL Server 2008 also has a Time data type that does the same thing in reverse, holding only the time portion.

Not having  a date data type meant you learned by heart the following:

CONVERT(datetime,CONVERT(char(10), datevalue, 121))

That stripped the time portion from a datetime and left you with the date. But now, you can just use:

CONVERT(date, datevalue)

Or just store the value as date, which is what I'm doing in my calendar of events, which has a number of holidays through 2020. If you'd like, you can grab the SQL Script from here.

Tags:

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment  Cancel 
 
 
  
 
Privacy Statement | Terms Of Use Copyright 2001-2008 by ReluctantDBA.com