Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

DATETIME, DATE and TIME datatypes and arithmetic operation

Sep 30 2014 12:00AM by Madhivanan   

In this post DATE and arithmetic operation we have known that we can not use arithmetic operation directly on DATE datatype as we use it for DATETIME datatype. In this post I am going to show you some other examples with DATE and TIME datatypes as well.
Let us consider these examples

declare @datetime datetime, @date date, @time time
select @datetime='2014-10-10',@date='2010-10-10',@time='16:17:22:456'
select @datetime+'16:17:22:456' 
The result is
2014-10-10 00:00:00.000
It means that you can directly add a time value to a DATETIME datype variable/column. But it is not possible to add TIME datatype value to DATETIME datatype value
declare @datetime datetime, @date date, @time time
select @datetime='2014-10-10',@date='2010-10-10',@time='16:17:22:456'
select @datetime+@time 
The error is
Msg 402, Level 16, State 1, Line 4
The data types datetime and time are incompatible in the add operator.
The possible option to add TIME value in this case is to CAST TIME value into DATETIME datatype
declare @datetime datetime, @date date, @time time
select @datetime='2014-10-10',@date='2010-10-10',@time='16:17:22:456'
select @datetime+cast(@time as datetime)
The result is
2014-10-10 16:17:22.457
Similary if you want to add DATE and TIME datatype, you should CAST both of them to DATETIME datatype
declare @datetime datetime, @date date, @time time
select @datetime='2014-10-10',@date='2010-10-10',@time='16:17:22:456'
select cast(@date as datetime)+cast(@time as datetime)
The result is
2014-10-10 16:17:22.457
So if you are using DATE and TIME datatypes be aware of these.

Tags: 


Madhivanan
2 · 40% · 13039
3
 
0
Lifesaver
 
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"DATETIME, DATE and TIME datatypes and arithmetic operation" rated 5 out of 5 by 3 readers
DATETIME, DATE and TIME datatypes and arithmetic operation , 5.0 out of 5 based on 3 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]