How to convert DateTime to VarChar

0 votes
I'm trying to convert a value from a DateTime variable to a varchar variable using the yyyy-mm-dd format (without time part).

How can I go about doing that?
Feb 22 in Database by Vaani
• 7,020 points
124 views

1 answer to this question.

0 votes

With Microsoft Sql Server:

--
-- Create test case
--
DECLARE @myDateTime DATETIME
SET @myDateTime = '2020-06-02'

--
-- Convert string
--
SELECT LEFT(CONVERT(VARCHAR, @myDateTime, 100), 20)
answered Feb 23 by Neha
• 8,940 points

Related Questions In Database

0 votes
0 answers

How to convert SQL Server's timestamp column to datetime format

Is there a simple way to convert ...READ MORE

Aug 21 in Database by Kithuzzz
• 20,460 points
532 views
0 votes
1 answer

SQL Server Convert Varchar to Datetime

Try this: SELECT CONVERT(Datetime, '2011-09-28 18:01:00', 120) -- ...READ MORE

answered Sep 13 in Database by narikkadan
• 37,260 points
525 views
0 votes
1 answer

how to Convert EST time to IST time in excel?

Use the following calculation since Indian Standard ...READ MORE

answered Mar 25 in Database by gaurav
• 22,040 points
336 views
0 votes
1 answer

How to convert a column number (e.g. 127) into an Excel column (e.g. AA)

If anyone needs to do this in ...READ MORE

answered Mar 30 in Database by gaurav
• 22,040 points
167 views
0 votes
1 answer

Difference between datetime and timestamp in sqlserver?

Timestamp is a synonym for rowversion, according ...READ MORE

answered Feb 16 in Database by Vaani
• 7,020 points
1,664 views
0 votes
1 answer

How Can I use "Date" Datatype in sql server?

There's problem in all of them and ...READ MORE

answered Feb 9 in Database by Neha
• 8,940 points
261 views
0 votes
1 answer

How Can I use "Date" Datatype in sql server?

Your dates are interpreted as MM-DD-YYYY. This ...READ MORE

answered Jun 21 in Others by nisha
• 2,190 points
76 views
0 votes
0 answers

How to convert java.util.Date to java.sql.Date?

I need a java.sql since I'm trying ...READ MORE

Aug 11 in Database by Kithuzzz
• 20,460 points
181 views
0 votes
1 answer

How to drop all tables from a database with one SQL query?

Use the INFORMATION_SCHEMA.TABLES view to get the ...READ MORE

answered Feb 4 in Database by Neha
• 8,940 points
1,052 views
0 votes
1 answer

How to rename a column in a database table using SQL?

For SQL Server, use sp_rename USE AdventureWorks; GO EXEC sp_rename 'Customers.CustomerTerritory.TerritoryID', ...READ MORE

answered Feb 9 in Database by Neha
• 8,940 points
139 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP