Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
zabronm
Starting Member
2 Posts |
Posted - 2009-07-01 : 04:59:17
|
| Please helpI have a string field that stores date in long date format: "Dec 2 2003 12:00AM" I want to convert this to a string like: "2003-12-02 00:00:00.000" so that I am able to extract individual parts of the date like, year, month and date. How can i do this? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-07-01 : 05:03:39
|
[code]DECLARE @s VARCHAR(200)SET @s = 'Dec 2 2003 2:23:32AM'SELECT @s, CONVERT(DATETIME, @s, 109)[/code] N 56°04'39.26"E 12°55'05.63" |
 |
|
|
zabronm
Starting Member
2 Posts |
Posted - 2009-07-01 : 05:22:03
|
quote: Originally posted by Peso
DECLARE @s VARCHAR(200)SET @s = 'Dec 2 2003 2:23:32AM'SELECT @s, CONVERT(DATETIME, @s, 109) N 56°04'39.26"E 12°55'05.63"
Magic!! thanks Peso - didnt know of the agument 109, however, had to use 111 and super.. |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-07-01 : 06:22:49
|
| Hi see this link it will be more useful to uhttp://www.sql-server-helper.com/tips/date-formats.aspx |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-07-01 : 12:07:12
|
quote: Originally posted by zabronm Please helpI have a string field that stores date in long date format: "Dec 2 2003 12:00AM" I want to convert this to a string like: "2003-12-02 00:00:00.000" so that I am able to extract individual parts of the date like, year, month and date. How can i do this?
if the field stores date values why make it varchar in first place? always try to use proper datatype for fields |
 |
|
|
|
|
|