How to convert date to a format mm dd yyyy

0 votes

I have a SQL table with a date field entitled CREATED TS that contains dates in various formats, such as. as depicted below:

Feb 20 2012 12:00AM
11/29/12  8:20:53 PM          
Feb 20 2012 12:00AM
11/29/12  8:20:53 PM          
Feb 20 2012 12:00AM
11/29/12  8:20:53 PM          
Nov 16 2011 12:00AM
Feb 20 2012 12:00AM
11/29/12  8:20:52 PM

Now that I'm comparing the dates in the WHERE clause of my SELECT query, I want to change these to the format mmddyyyy before.

I tried using:

CONVERT(VARCHAR(10),CREATED_TS,101)

But got the result as,

Feb 20 201
11/29/12  
Feb 20 201
11/29/12  
Feb 20 201
11/29/12  
Nov 16 201
Feb 20 201
11/29/12  

I need the result eg. 02/20/2012 in order to compare. 

Sep 8, 2022 in Database by Kithuzzz
• 38,000 points
4,466 views

1 answer to this question.

0 votes

Your data is already in varchar, thus you must first convert it to date:

select convert(varchar(10), cast(ts as date), 101) from <your table>

I hope this helps you.

answered Sep 10, 2022 by narikkadan
• 63,600 points
0 votes
My date of birth change
answered Feb 23, 2023 by anonymous

edited Mar 5

Related Questions In Database

+1 vote
1 answer

how to change format of date from mm/dd/yyyy to dd-mmm-yyyy in MS Excel

i am using in angular its work ...READ MORE

answered Apr 13, 2023 in Database by manisha

edited Mar 5 159,701 views
0 votes
1 answer

Convert Date format into DD/MMM/YYYY format in SQL Server

Using convert() and style 106, you can ...READ MORE

answered Feb 23, 2022 in Database by Vaani
• 7,070 points
14,535 views
0 votes
1 answer

How to convert date to general in excel without losing format?

The steps are as follows: Copy the dates ...READ MORE

answered Apr 1, 2022 in Database by gaurav
• 23,260 points
43,011 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
1,121 views
0 votes
0 answers

How to update Identity Column in SQL Server?

With 200 records currently, I want to ...READ MORE

Aug 9, 2022 in Database by Kithuzzz
• 38,000 points
1,539 views
0 votes
0 answers

Simple DateTime sql query

How do I query the DateTime database ...READ MORE

Aug 12, 2022 in Database by Kithuzzz
• 38,000 points
687 views
0 votes
0 answers

How can I select the first day of a month in SQL?

I only need to choose the given ...READ MORE

Aug 14, 2022 in Database by Kithuzzz
• 38,000 points
890 views
0 votes
0 answers

CROSS JOIN vs INNER JOIN in SQL

What is the difference between CROSS JOIN and INNER JOIN? CROSS ...READ MORE

Aug 18, 2022 in Database by Kithuzzz
• 38,000 points
674 views
0 votes
0 answers
0 votes
0 answers

Convert date from dd-mm-yyyy to yyyy-mm-dd in SQL Server

Given date: DECLARE @Date1 VARCHAR(50) = '30-01-2015' I want ...READ MORE

Aug 18, 2022 in Database by Kithuzzz
• 38,000 points
6,369 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