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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert varchar to date field

Status
Not open for further replies.

pleashelp

Technical User
Feb 27, 2002
97
US
New to SQL codes. Using SQL 2005. I have a varchar field that is a date. I need to convert this to an actual date field. I was given this piece of code

dbo.fn_datetodisplaydate(dbo.fn_chartodate(DateOfReferral))

where DateOfReferral is the field name. The problem is that this code give me a 2 digit year, e.g. 03/01/10. What I need is a 4-digit year to display in the results, e.g. 03/01/2010. Can someone tell me how to do this?

Thanks..
 
Look up convert or cast from BOL:
eg
select convert(varchar, DateOfReferral,120)
 
Thanks for your reply. This:
select convert(varchar, DateOfReferral,120)

gives me 20100301. I really need it to be 03/01/2010 if that is at all possible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top