

The STUFF function inserts a string into another string. Includes all (yy) (without century) styles and a subset of (yyyy) (with century) styles. 1These style values return nondeterministic results. This approach will work if your string is always the same length and format, and it works from the end of the string to the start to produce a value in this format: YYYYMMDD HH:MM:SSįor this, you don't need to separate the date portion in anyway, as SQL Server will be able to understand it as it's formatted. SQL Server supports the date format, in Arabic style, with the Kuwaiti algorithm. Nevertheless, your method will prove handy should I need to convert a stupiddate created by a moron to a DATE column. This allows me to join it to a fact table which has a DateKey column with that format. I just need to create a column with the YYYYMMDD format. Using FORMAT you can format datetime value as you wish. In SQL Server 2012, Microsoft introduced a built-in string function called FORMAT. Before SQL Server 2012, we used CONVERT to format the date. SELECT CONVERT(DATETIME, AS FormattedDate The date format was fine, it is just a date column no string attached. Frequently, you may need to convert the datetime value to a specific formatted date like YYYY-MM-DD. You can use the STUFF() method to insert characters into your string to format it in to a value SQL Server will be able to understand: DECLARE NVARCHAR(20) = '20120225143620'
