Is there any difference in performance or storage when using Date vs DateTime?

When using SQL Server and ASP.NET, is there a performance / storage relationship when using Datevs DateTime?

Even if I don’t need it, I used DateTimefor most things

+3
source share
3 answers

DateTime takes 8 bytes per value

Date is 3 bytes.

I can not talk about the low level of performance; however, as a rule, we found an error to store values ​​as DateTime by default. Sooner or later, you will encounter the UTC problem and have to start developing offsets for dates that have 00: 00: 00.000 in the time part!

, Date;

+6

, . - 3 , DateTime - 8 . , . , . , smalldatetime, , .

SQL

+1

:

  • : sql ( ) ,
  • : DATE SQL Server 2008, SQL Server 2005
  • .NET: no DATE .NET - DATE DateTime.NET Class
  • LINQ: LINQ2SQL ( SQL Metal) DATE SQL
  • DateTime CAST(@myDateTimeParam AS DATE)

: T-SQL #

( ):

DECLARE @startDay DATE = '2012-04-11' -- day
DECLARE @endDay DATE = '2012-04-13' -- day
DECLARE @eventTime DATETIME = '2012-04-13 12:00' -- point in time (noon)

IF @eventTime BETWEEN @startDay AND @endDay PRINT 'In period.' ELSE PRINT 'Not in period!'

:

Not in period!

BETWEEN @endDay DateTime ( , @eventTime), - .

:

DECLARE @startDay DATE = '2012-04-11' -- day
DECLARE @endDay DATE = '2012-04-13' -- day
DECLARE @eventTime DATE = '2012-04-13' -- day

IF @eventTime BETWEEN @startDay AND @endDay PRINT 'In period.' ELSE PRINT 'Not in period!'

:

In period.

:

DECLARE @startDay DATETIME = '2012-04-11' -- day, but point in time in fact 00:00.000
DECLARE @endDay DATETIME = '2012-04-13' -- day, but point in time in fact 00:00.000
DECLARE @eventTime DATETIME = '2012-04-13' -- day, but point in time in fact 00:00.000

IF @eventTime BETWEEN @startDay AND @endDay PRINT 'In period.' ELSE PRINT 'Not in period!'

:

In period.
+1

All Articles