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

Converting Character Data to Date Data

Status
Not open for further replies.

DBADoug

Programmer
Oct 25, 2000
27
US
Is there a way to convert the following eight character string into a valid SQL Server date field? I am assuming the year is 2003.

10260010

10 is the month
26 is the day
0010 is the time in military format (in this example, 10 miniutes after midnight)

Thanks ...
 
Try this (I didn't have time to test it). If it's not what you want, maybe it'll give you an idea for solving it....

DECLARE @mymonth INT
, @myday INT
, @myhour INT
, @mymin INT
SET @mymonth = (SELECT SUBSTRING(columnname, 1, 2) FROM mytable)
SET @myday = (SELECT SUBSTRING(columnname, 3, 2) FROM mytable)
SET @myhour = (SELECT SUBSTRING(columnname, 5, 2) FROM mytable)
SET @mymin = (SELECT SUBSTRING(columnname, 7, 2) FROM mytable)

SELECT '2003' + '-' + @mymonth + '-' + @myday + ' ' + @myhour + ':' + @mymin


-SQLBill
 
This definately points me in the right direction. Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top