SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 datediff function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

joe8079
Posting Yak Master

USA
127 Posts

Posted - 05/15/2013 :  10:09:27  Show Profile  Reply with Quote
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

USA
127 Posts

Posted - 05/15/2013 :  10:17:14  Show Profile  Reply with Quote
I actually just figured it out: CONVERT(DATETIME, datefield, 102)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 05/16/2013 :  00:28:59  Show Profile  Reply with Quote
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 convertion

http://visakhm.blogspot.in/2011/12/why-iso-format-is-recommended-while.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000