Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Converting string to datetime format Expand / Collapse
Author
Message
Posted Thursday, April 23, 2009 8:03 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, December 3, 2013 9:48 AM
Points: 18, Visits: 97
Hi,

I´m hoping somebody can help with this. I need to convert a set of dates (in string format) to the datetime data type.

The data is currently stored as strtings in the following format:

Monday, January 28, 2008


Thanks in advance
Post #703222
Posted Thursday, April 23, 2009 8:38 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 3:58 PM
Points: 5,359, Visits: 8,921
Try this:
declare @testdate varchar(50), @realdate datetime
set @testdate = 'Monday, January 28, 2008'
set @realdate = SUBSTRING(@testdate, CharIndex(', ', @testdate)+2, 50)
select @testdate, @realdate



Wayne
Microsoft Certified Master: SQL Server 2008
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
Post #703259
Posted Thursday, April 23, 2009 8:43 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 13,872, Visits: 9,596
Please don't double-post in multiple forums.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #703268
Posted Thursday, April 23, 2009 8:47 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 3:58 PM
Points: 5,359, Visits: 8,921
Ahh, didn't consider double-posting. I thought that I had posted that reply, but then I second-guessed myself and figured that I just didn't click the post button...

Wayne
Microsoft Certified Master: SQL Server 2008
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
Post #703273
Posted Thursday, April 23, 2009 9:03 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 13,872, Visits: 9,596
Sorry, wasn't aiming that comment at you, Wayne. Was meant for the OP.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #703300
Posted Friday, April 24, 2009 4:44 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, December 3, 2013 9:48 AM
Points: 18, Visits: 97
Hi GSquared,

I did try to delete my first post so as not to double post, but it wouldn´t let me.

Cheers

David
Post #703838
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse