0 votes
1 view
in SQL by (20.3k points)

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?

1 Answer

0 votes
by (40.4k points)

In Microsoft SQL Server, try using this code:

--

-- Create test case

--

DECLARE @myDateTime DATETIME

SET @myDateTime = '2008-05-03'

--

-- Convert string

--

SELECT LEFT(CONVERT(VARCHAR, @myDateTime, 120), 10)

Related questions

0 votes
1 answer
asked Jul 30, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...