Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

format dates correctly to mm/dd/yyyy

Status
Not open for further replies.

ciarra41

Technical User
Sep 11, 2006
116
US

I have these dates fomatted like these mm/dd/yy to mm/dd/yyyy I tried to convert function but to luck

01/21/98
07/17/96
12/15/04

Need them to look like this"
01/21/1998
07/17/1996
12/15/2004

any help would do
 
I suspect you are storing your data in a varchar column, which is unfortunately because it is entirely possible to store bad dates since it is just a string.

In order to do this, you could first convert to date time and then convert back to string. To convert to datetime, you should use the style argument to ensure that you are using mm/dd/yy and then use the style argument to ensure you have mm/dd/yyyy.

Like this:

Code:
Select  Convert(VarChar(10), Convert(DateTime, YourColumnNameHere, 1), 101)
From	YourTableNameHere

If you get a conversion error when you run the code above, it is an indication that you have invalid dates in your table.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top