Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
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.7k 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
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 30, 2019 in SQL by Tech4ever (20.3k points)

Browse Categories

...