GETDATE()
returns a datetime
value. When you do SELECT GETDATE()
, then the application is getting a datetime value and figuring out how to display it. The application you are using is wisely choosing an ISO-standard format.
When you do LEFT(GETDATE()
, then the database needs to do an implicit conversion from datetime
to some string value. For this, it uses its internationalization settings. What you are seeing is based on these settings.
Moral of the story: avoid implicit conversions. Always be explicit about what you are doing, particularly in SQL which has rather poor diagnostic capabilities. So, use CONVERT()
with the appropriate format for what you want to do.
convert(date,getdate())
– DecurvedSELECT FORMAT(SYSDATETIME(), 'yyyy-MM-dd');
to get exactly what you need .... – EncyclopedistFORMAT(GETDATE(),'YYYY-MM-DD')
, and changing the order and separators of the date fields. You can include Sam's code to stringify it if needed. – Gertie