Back
I am working on a query in SQL Server 2005 where I need to convert a value in DateTime variable into a varchar variable in yyyy-mm-dd format (without time part). How do I do that?
In Microsoft SQL Server, try using this code:
---- Create test case--DECLARE @myDateTime DATETIMESET @myDateTime = '2008-05-03'---- Convert string--SELECT LEFT(CONVERT(VARCHAR, @myDateTime, 120), 10)
--
-- Create test case
DECLARE @myDateTime DATETIME
SET @myDateTime = '2008-05-03'
-- Convert string
SELECT LEFT(CONVERT(VARCHAR, @myDateTime, 120), 10)
31k questions
32.8k answers
501 comments
693 users