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 |
joe8079
Posting Yak Master
127 Posts |
Posted - 2013-05-15 : 10:09:27
|
I have a table where the data type for the datetime field is in char(26) and not datetime. How would I do a datediff on the field below if it is in char(26) datatype instead of datetime. 2013-03-21-03.00.00.543756 |
|
joe8079
Posting Yak Master
127 Posts |
Posted - 2013-05-15 : 10:17:14
|
I actually just figured it out: CONVERT(DATETIME, datefield, 102) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-16 : 00:28:59
|
quote: Originally posted by joe8079 I actually just figured it out: CONVERT(DATETIME, datefield, 102)
be careful on format in which date values are stored in char field. Unless they're all in consistent and in valid format as per your regional/language settings code can break. In case there are multiple formats present do a series a batch updates to make them all into consistent format before you apply above convertionhttp://visakhm.blogspot.in/2011/12/why-iso-format-is-recommended-while.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|