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 string field to time

Status
Not open for further replies.

pleashelp

Technical User
Feb 27, 2002
97
US
Using SQL 2005. Have a char field called 'StartTime' that shows a time such as '0815' or '1430'. It seems like it should be a simple thing to convert this field to an actual time field so that it displays '8:15 am' or '2:30 pm'. Any help in doing this would be greatly appreciated. Thanks
 
This is close - but no space
Code:
select right(convert(varchar(30),cast (stuff('0815', 3,0,':') as datetime),100),7)
select right(convert(varchar(30),cast (stuff('1430', 3,0,':') as datetime),100),7)

PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top