Offhand, I'd say you're better off not doing that. Leave the columns in datetime format internally in the table so that you can take advantage of date/time manipulation functions that most databases have available these days. If all you are interested in is the date for display purposes, it's easy enough to use those same built-in functions to display only that part of the field desired. There's also a good chance that you'll see a size savings on those fields as well, since they'll be in datetime format instead of string.|||If you're trying to format a default date column, try something to the effect of:
CREATE TABLE table
( col1 INT PRIMARY KEY
, date_col VARCHAR(16) DEFAULT CONVERT(VARCHAR(16), getDate(), 101)
A formatting chart is available at: http://msdn2.microsoft.com/en-us/library/ms187928.aspx
If you only want just the YYYY part of the date try using the RIGHT() function
RIGHT(CONVERT(VARCHAR(16), getDate(), 101), 4)
would get you the year of todays date.
It's been a little while since I've used MS's flavor of SQL, but I belive that syntax is correct.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment