format different sql dates into mm/dd/yyyy format

I have an sql server 2012 order table that has dates in various formats stored in a varchar field  

here is a sample

order id
    1                     Null
    2                   12-01-2017
    3                    01/01/93
    4                    01/03/16
    5                     12/01/1999
     6                    2-2-07

trying to write a query that would "force" dates into mm/dd/yyyy format

(no year is before1990)

if the date is null would like it formatted as 01/01/1900

given the sample I would like to see

ordered  date
1               01/01/1900
2               12/01/2017
3                01/01/1993
4                01/03/2016
5                12/01/1999
6                02/02/2007
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
What DBMS are you using (SQL Server, Oracle, MySQL, ...)?
johnnyg123Author Commented:
ms sql server 2012
Bill PrewIT / Software Engineering ConsultantCommented:
Give this a try.

SELECT [Line], CONVERT(date, IsNull([order id], '1-1-1900')) AS [order id] FROM
(SELECT 1 AS [Line], NULL AS [order id]
SELECT 2 AS [Line], '12-01-2017' AS [order id]
SELECT 3 AS [Line], '01/01/93' AS [order id]
SELECT 4 AS [Line], '01/03/16' AS [order id]
SELECT 5 AS [Line], '12/01/1999' AS [order id]
SELECT 6 AS [Line], '2-2-07' AS [order id]) As t1

Open in new window

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Garfield SamuelsProject ManagerCommented:

SELECT convert(datetime, [ordered  date], 101)
Mark WillsTopic AdvisorCommented:
You can use FORMAT, but need to check if it is a date to use format

e.g. select iif(isdate(yourdate) = 1,format(cast(yourdate as date),'d','en-US'),'01/01/1900')

That leaves it as a string, or convert to a date data type...

select iif(isdate(yourdate) = 1,cast(yourdate as date),'1900-01-01')

edit : select iif(isdate(yourdate) = 1,format(cast(yourdate as date),'MM\/dd\/yyyy'),'01/01/1900')
Scott PletcherSenior DBACommented:
If all the dates are good, you can do something like this:

SELECT CONVERT(varchar(10), CAST(NULLIF(column_name, 'NULL') AS date), 101)

Btw, that format seems like a bad idea, since it doesn't compare accurately nor sort accurately.  You should consider using yyyy-mm-dd.
Dean ChafeeIT/InfoSec ManagerCommented:
udpate [tblname] set [order date]  = replace( CAST([order date] AS varchar),'-','/')  where isdate([order date]) =1;
udpate [tblname] set [order date]  = '01/01/1900'  where [order date] = NULL;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NerdsOfTechTechnology ScientistCommented:
TRY_CONVERT is a safe approach to the date conversion as on error (from say a malformed or invalid date) it returns null; this null and a natural null can then default to 01/01/1900.
 IsNull(TRY_CONVERT(DATE, `order_date`, 101), CONVERT(DATE,'01/01/1900')) AS `ordered_date`
 FROM orders

Open in new window

johnnyg123Author Commented:
Thanks too all that responded
needed is date check as part of it
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.