Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Integer/Numeric value assigned to Datetime type variable

$
0
0

A variable declared of DateTime type accepts Integer and NUmeric values , where as rest data types in the same group (DATE,TIME,DATETIME2) doesn't accept.

If an integer value is assigned , SQL server returns a datetime value with those No. of days added to 1900-01-01 value.

When a numeric value is assigned , the integer part is considered as no.of days and the decimal value into time(o.1 means 2.24 hours).

declare @date date,@datetime datetime,@time time,@datetime2 datetime2

--set @date=1990
set @datetime=1990.1
--set @time=1990
--set @datetime2=1990
select @date,@datetime,@time, @datetime2

Does any one noticed this kind of behavior with datetime?


Thanks
Sarat

Please use Marked as Answer if my post solved your problem and useVote As Helpful if a post was useful.




Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>