How to convert DateTime to VarChar

datetime, sql, sql-convert, sql-server

Solution

With Microsoft Sql Server:

--
-- Create test case
--
DECLARE @myDateTime DATETIME
SET @myDateTime = '2008-05-03'

--
-- Convert string
--
SELECT LEFT(CONVERT(VARCHAR, @myDateTime, 120), 10)

Problem

I need to convert a value which is in a `DateTime` variable into a `varchar` variable formatted as `yyyy-mm-dd` format (without time part). How do I do that?

Original source

Related problems