Home »
Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Format DateTime in SQL

1 comment
In SQL Server, when we want to format DATETIME value, we can use CAST or CONVERT function to convert DATETIME to VARCHAR with a specific format.
The different between two function is:
When you use CAST, it change the DATETIME value to the type of data that you specified
For example:
SELECT CAST(GETDATE() AS VARCHAR(23))
--RETURNS 'Jan  1 2011 10:48PM'
But when you use CONVERT function, you can change the date format
SELECT CONVERT(VARCHAR(23), GETDATE(), 103)
--RETURNS 01/01/2011
103 here is the default format style