Content area
Full text
Date/Time Conversions Code Correction
Thanks to Susan Perschke for her great article, "Automate Date/Time Conversions" (March 2007, InstantDoc ID 94954). I just finished a project where I had to do exactly what Susan described in Listing 1 and created a uniqueness database file (UDF) that does the same thing. From her article, I thought I might create a couple more handy date/time-related UDFs. I ran into a snag with her sp_format_dt. The "set @ result = convert(char(20), convert(datetime, @dt, @code_in), @code_out)" statement failed for me. After consulting the SQL Server documentation, I believe it specifies that you can use only the Style parameter when converting to a STRING type (nchar, nvarchar, char, varchar, nchar, or nvarchar data types). The part "convert(datetime, @dt, @code_in)" doesn't seem to work. Instead, what I get is an error: Conversion failed when converting datetime from character string. Am I right about this, or am I missing something about this statement?
-Jack Rosa
Thank you for the compliment, Jack, and for the feedback. As sometimes happens, the original code was modified during the editing process, and I have to confess that I dropped the ball on retesting the code before the article went to print. We've corrected the code back to the original for the stored procedure, and you can access it...





