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

datetime conversion 1

Status
Not open for further replies.

Chumley40

Programmer
Jan 24, 2005
71
US
I need to convert a varchar field that returns datetime in the format of May-18-09 14:00 into a datetime field. When I do a simple cast (fieldname as datetime) I get an overflow. Does anyone know how to cast or convert this format in sql as a datetime?

Thanks in advance,
TJ
 
Hi TJ

Try
Code:
select convert(datetime, replace('May-18-09 14:00', '-', ' '), 109)

The format 109 wants the format to be
mon dd yyyy hh:mi:ss:mmmAM (or PM)

Using the replace function creates that format.


Hope it helps

Kevin

**************************************************************
Rock is Dead (Long Live Paper and Scissors)
**************************************************************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top