I know that it is possible to reformat the DateTime data type of the current date and time by using select convert. However, I havent been able to find a method to reformat an existing column (DateTime data type) to: hh:mm:ss yyyy/mm/dd. Or even better, I would like to reformat it to show time only. I dont want to simply convert to time data type because I am working with a chart that accepts either Date or Date time. But what I really want to display on that specific axis of the chart is time. Is there any way to reformat DateTime to my requirements? Thanks.
Share
SQL Server’s
convertfunction can take an optionalstyleargument depending upon the datatype. This is how you can get a datetime converted to a string in a variety of formats. For example, try running:You can replace
getdate()in this example with a column name as well.There are many styles available, as shown in the documentation.
Note that you will be returning a varchar, so you may want to sort by the original column’s datatype.