In SQL Server, you can use use the CONVERT()
function to convert a date value from one date data type to another (or between any other data type for that matter). However, that’s not the only function in the T-SQL toolbox for converting between data types.
The CAST()
function is part of the ANSI SQL standard, and it does most of the things CONVERT()
does. So in many cases, you have the option of which of these functions you prefer to use.
Many database professionals prefer CAST()
due to the fact that it’s part of the ANSI SQL standard, however, others prefer CONVERT()
due to the extra functionality that T-SQL’s implementation offers (such as being able to provide a date style).
In any case, this article provides examples of converting between different date formats using CAST()
.