Sometimes when working with databases and other programming environments, you get a date value but it’s in the wrong format/data type. For example, if a date has been generated with an inbuilt date function, it might include both the date and the time, right down to the last nanosecond. And all you want is the day, month, and year, say like this: 2018-01-01.
If this happens while you’re using SQL Server, you can use the CONVERT()
function to convert it to another data type. When you do this, the data type will determine the format it appears as.
This article provides examples of using the CONVERT()
function in SQL Server to convert a date value to another (date) data type.