| Author |
Topic |
|
sqlchiq
Posting Yak Master
133 Posts |
Posted - 2008-08-14 : 16:27:10
|
| I have a bunch of entries that are like8/8/2008 5:45:33 PM8/8/2008 5:45:41 PM8/8/2008 5:45:50 PM8/8/2008 5:45:41 PM8/8/2008 5:45:59 PMBut are essentially 8/8/2008 (in nvarchar datatype)I was wondering if there was a simple way to change all of it intosmalldatetime8/8/2008 0:00:00or whatever |
|
|
jdaman
Constraint Violating Yak Guru
354 Posts |
Posted - 2008-08-14 : 16:57:48
|
| dateadd(dd, datediff(dd, 0, YourDateHere), 0) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-18 : 04:26:01
|
| dateadd(dd, datediff(dd, 0, cast(YourDateHere as datetime)), 0)MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-18 : 04:36:22
|
quote: Originally posted by madhivanan dateadd(dd, datediff(dd, 0, cast(YourDateHere as datetime)), 0)MadhivananFailing to plan is Planning to fail
just a doubt wont the nvarchar value be implicitly casted? is there a need for explicit casting? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-18 : 05:08:32
|
quote: Originally posted by visakh16
quote: Originally posted by madhivanan dateadd(dd, datediff(dd, 0, cast(YourDateHere as datetime)), 0)MadhivananFailing to plan is Planning to fail
just a doubt wont the nvarchar value be implicitly casted? is there a need for explicit casting?
Once I got convertion failed error but I am not able to reproduce it nowMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-18 : 05:24:37
|
quote: Originally posted by madhivanan
quote: Originally posted by visakh16
quote: Originally posted by madhivanan dateadd(dd, datediff(dd, 0, cast(YourDateHere as datetime)), 0)MadhivananFailing to plan is Planning to fail
just a doubt wont the nvarchar value be implicitly casted? is there a need for explicit casting?
Once I got convertion failed error but I am not able to reproduce it nowMadhivananFailing to plan is Planning to fail
Ok. just checked as i didnt get one |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-08-18 : 06:44:13
|
UPDATE Table1SET Col1 = LEFT(Col1, CHARINDEX(' ', Col1)) + '00:00:00 AM' E 12°55'05.25"N 56°04'39.16" |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-08-18 : 08:36:08
|
quote: Originally posted by visakh16just a doubt wont the nvarchar value be implicitly casted? is there a need for explicit casting?
I personally like to do the explicit casts/converts if I want the result in a specific datatype. One reason is I don't want to count different/future versions to behave the same way, and another reason is for the benefit of other developers so they can easily see what my intentions were. It is not necessary but it is a convention that I started using. When I remember to :)Be One with the OptimizerTG |
 |
|
|
|