

You can read more about the available date/time styles on the Microsoft website. Jby Bijay In this SQL Server tutorial, we will learn How to convert Datetime datatype to String in SQL Server, Different SQL Server convert DateTime to string examples, and cover the below topic. Microsoft warns that this value does not render correctly on a default US installation of SSMS. Styles 120 to 127 DECLARE datetime2 = '' Styles with Two Digit Yearsīelow are examples of the various values you can use to specify the style using a two digit year component.

If you need it to be returned in a different style, you’ll need to specify a third argument. However, you’ll get a different result if the original data type is not datetime or smalldatetime. Therefore, when you don’t provide a style (third parameter), this is how it’s styled: DECLARE datetime = AS Original, The default style when converting from the datetime and smalldatetime data types is 0 and 100 (these represent the same style). This article contains examples of the various styles you can return when converting a date/time value to a string using the CONVERT() function in SQL Server. For example, you can have it returned as dd.mm.yyyy, yyyy-mm-dd, dd mon yyyy, etc

It’s similar to the CAST() function, but one of the benefits of CONVERT() is that, when you convert from a date/time data type to a string, you can add an optional argument that specifies the style that you want the return value to be in. The CONVERT() function allows you to convert between data types.
