I found this in some code that I was tasked with documenting:
SELECT CONVERT(CHAR(10), GETDATE(), 103)
I ... don't get it. The first arg should be a data_type
, not a string.
How is "LineFeed" a valid data_type?
It runs, and returns today's date (in SQL Server) so I must be missing something blindingly obvious.
CHAR is a valid data type, in addition to being a function.
The parser is intelligent enough to know that in this context, CHAR is being used as a datatype.
The CONVERT()
function takes 3 arguments:
Your line SELECT CONVERT(CHAR(10), GETDATE(), 103)
meets this signature:
CHAR(10)
GETDATE()
103
The GETDATE()
expression returns a DATETIME
object which is converted to a CHAR(10)
in the style specified by 103
(which is dd/mm/yyyy
as per the site I linked to above).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With