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 |
|
dibblejon
Starting Member
36 Posts |
Posted - 2012-04-25 : 09:52:57
|
| HiI need to convert a datetime column in a table which pulls it's data in from a third party app.It's raw state is 2011-11-25 07:33:00.000I want to convert this so I just get the YYYY-MM-DD and I want to retain as a date formatted field.Apologies if this has been covered a million times before! |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-04-25 : 09:55:58
|
selectconvert(date,'2011-11-25 07:33:00.000') No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2012-04-25 : 09:56:28
|
| If your'e on sql 2008 you could simply do select cast('2011-11-25 07:33:00.000' as date). If you're on 2005 or older you have to have the time-part in there as well if you want to use a datetime datatype- LumbagoMy blog-> http://thefirstsql.com/2011/07/08/how-to-find-gaps-in-identity-columns-at-the-speed-of-light/ |
 |
|
|
dibblejon
Starting Member
36 Posts |
Posted - 2012-04-25 : 10:04:00
|
Please forgive my ignorance.... Or poor explanationI have just run:SELECT CONVERT(date, CALLDATEANDTIME) AS DateFROM dbo.CALLS But get an error saying Error Message: Cannot call methods on dateThe field called CALLDATEANDTIME is the field I am trying to convert.What am I doing incorrectly? |
 |
|
|
dibblejon
Starting Member
36 Posts |
Posted - 2012-04-25 : 10:13:40
|
| Found what I needed DATEADD(dd, 0, DATEDIFF(dd, 0, CALLDATEANDTIME)) Returns YYYY-MM-DD 00:00:00.000Which is fine for what we need. |
 |
|
|
|
|
|