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, 2022 in Database by Vaani
• 7,070 points
1,163 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, 2022 by Neha
• 9,020 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, 2022 in Database by Kithuzzz
• 38,020 points
1,577 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, 2022 in Database by narikkadan
• 63,680 points
6,197 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, 2022 in Database by gaurav
• 23,260 points
1,998 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, 2022 in Database by gaurav
• 23,260 points
999 views
0 votes
1 answer

Difference between datetime and timestamp in sqlserver?

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

answered Feb 16, 2022 in Database by Vaani
• 7,070 points
4,864 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, 2022 in Database by Neha
• 9,020 points
1,327 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, 2022 in Others by nisha
• 2,210 points
580 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, 2022 in Database by Kithuzzz
• 38,020 points
790 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, 2022 in Database by Neha
• 9,020 points
8,936 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, 2022 in Database by Neha
• 9,020 points
738 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