SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Downloaden Sie, um offline zu lesen
New Date Datatypes in SQL Server 2008 | TechRepublic



   ZDNet Asia   SmartPlanet    TechRepublic                                                                                     Log In    Join TechRepublic     FAQ     Go Pro!




                                                  Blogs     Downloads        Newsletters       Galleries       Q&A   Discussions         News
                                              Research Library


    IT Management             Development         IT Support        Data Center         Networks         Security




    Home / Blogs / The Enterprise Cloud                                                   Follow this blog:

    The Enterprise Cloud


    New Date Datatypes in SQL
    Server 2008
    By Tim Chapman
    September 8, 2008, 10:59 AM PDT

    Takeaway: SQL Server 2008 provides new data-types for storing wider ranges of dates with
    more precision. Heres can you can use these new data types to your advantage in SQL Server
    2008.

    As a database architect, one of the features I am most excited about in SQL Server 2008 is the
    new date related data types. These data types allow for the storage of time-only data, date-only
    data, a larger range of date values, more time precision, and the ability to store time-zone specific
    dates. Today I’ll take a look at these great new data types and how they can be used to expand
                                                                                                                           Btrieve 6.15 Forever
    your date storage possibilities.
                                                                                                                           Still using Btrieve? So are we! Get the Ultimate

    DATE
                                                                                                                           Btrieve Patch
                                                                                                                           pervasivedb.com/btrieve
    The new DATE data-type defines a date field without any associated time. In previous versions of                       Improve Productivity
    SQL Server, storing time-only data was accomplished in one of two ways. First, you could define                        Apps For Business- 30 Day Free Trial. No
    either a DATETIME or SMALLDATETIME data type and assign the value as a VARCHAR value.                                  Credit Card Required!
    Then you would need to handle the time related data in your queries. The other way is to store the                     www.google.com/apps
    date value in a VARCHAR field in the database. Either way, handling date-only data was at best                         OTM (G-Log) Solutions
    cumbersome. With the new DATE data-type, it intrinsically stores only date values. In the following                    At MavenWire, We Offer Solutions to Meet
    example I define a DATE data-type and a DATETIME data type and assign today’s date to the                              Your Business Needs. Visit Us!
    variables. As you can see from SELECTing the values from the variables, the DATE variable holds                        www.MavenWire.com
    only the date portion whereas the DATETIME field also stores the associated time from the
    GETDATE() function.

    DECLARE @TodaysDate DATE = GETDATE()

    DECLARE @TodaysDateTime DATETIME = GETDATE()
                                                                                                                      Keep Up with TechRepublic
    SELECT @TodaysDate, @TodaysDateTime

    Storing DATE specific data will also make queries easier to write. Instead of using one of the
    following statements to pull data for a DATETIME column;
                                                                                                                       
                                                                                                                            Five Apps
    SELECT * FROM SalesHistory
                                                                                                                       
                                                                                                                            Google in the Enterprise
    WHERE SaleDate = ‘4/11/2008' AND SaleDate  ‘4/12/2008'

    you can use an equality operator (=) to search only for the specific date, assuming the                                Subscribe Today
    SaleDateOnly field is defined as a DATE data-type.

    SELECT * FROM SalesHistory                                                                                        Follow us however you choose!
    WHERE SaleDateOnly = ‘4/11/2008'




http://www.techrepublic.com/blog/datacenter/new-date-datatypes-in-sql-server-2008/443[08/29/2012 3:44:51 PM]
New Date Datatypes in SQL Server 2008 | TechRepublic




    DATETIME2
    This data type is very simiilar to the datetime data type present in previous versions of SQL
    Server. The difference is the time precision and the range of dates that DATETIME2 can store.
    The new DATETIME2 data type can hold a range of dates from 0001-01-01 through 9999-12-31
    while DATETIME holds the date range from 1753-01-01 to 9999-12-31. Another benefit of this                 Media Gallery
    data type is the precision in which it records time. DATETIME2 is accurate to within 100
    nanoseconds whereas DATETIME is accurate to within 3/1000 of a second. The following script
    compares the values that the DATETIME and the DATETIME2 data-types can hold.

    DECLARE @DateTime2 DATETIME2 = GETDATE()

    DECLARE @DateTime DATETIME = GETDATE()                                                                           PHOTO GALLERY (1 of 15)

    SELECT @DateTime, @DateTime2
                                                                                                                     Curiosity's autonomous
                                                                                                                     'seven minutes of...
    Notice the additional precision stored in the DATETIME2 variable. This additional data can be of
                                                                                                                           More Galleries »
    major significance for those applications where time related information is mission-critical.

    TIME
    The TIME data-type stores only the time portion of a date. This is significant in that the time data
    can be stored seperately and not associated with a specific date. The TIME data-type, like the
    DATETIME2 data-type is accurate up to 100 nanoseconds. The following script compares the time
    specific information returned by the TIME data type and that which is returned from a DATETIME                   VIDEO (1 of 13)
    data type.                                                                                                       Cracking Open: HTC Titan II

    DECLARE @Time TIME = GETDATE()                                                                                          More Videos »
    DECLARE @DateTime DATETIME = GETDATE()

    SELECT @Time, @DateTime
                                                                                                               Hot Questions                     View All
    DATETIMEOFFSET
                                                                                                                3     SSL redirection
    The new DATETIMEOFFSET data type combines the range and precision of the DATETIME2
    data-type along with time-zone awareness based on a 24 hour clock. The time-zone awareness is
    accomplished by adding or subtracting an hours + minutes value to the date data. In the following
    example, I define a temporary table that holds two fields. The first field holds the date that is local     2     can anyone suggest if any such
    to my area. The second field, BeijingTime, is an offset date that will hold the time in Beijing, China;           software exist with similar
    which happens to be 12 hours ahead of the time in Louisville, KY.                                                 functionality?

    CREATE TABLE #OffSets
                                                                                                                3     Switching from a Job to a career in
    (                                                                                                                 the IT field: Need an IT pro's
             LouisvilleTime DATETIME2 DEFAULT(GETDATE()),
                                                                                                                      advice

             BeijingTime AS CONVERT(VARCHAR(50), LouisvilleTime, 121) + '+12:00'
                                                                                                                2     windows 7 won't shutdown and
    )                                                                                                                 keeps switching on
    INSERT INTO #OffSets(LouisvilleTime)

    SELECT GETDATE()                                                                                           Ask a Question
    SELECT * FROM #OffSets

    As you can see from the results from the table, the BeijingTime field holds the date from the
    LouisvilleTime field along with a 12 hour offset to indicate Beijing time. This data-type greatly          Hot Discussions                   View All
    enhances the ability to create time-zone aware applications.
                                                                                                               221    Should developers be sued for
    TIME to try the new data-types                                                                                    security holes?

    The new date related data-types included in SQL Server 2008 greatly expand the database
    developers ability to not only store a wider range of dates and precision for those dates, but also         79    The sitting duck that is open
    the ability to zone time-zone specific data which can lead to more robust and accurate reporting of               source
    time-related data around the world.
                                                                                                                27    Five fast Windows desktop search
                                                                                                                      utilities
    Get IT Tips, news, and reviews delivered directly to your inbox by subscribing to TechRepublic’s free
    newsletters.                                                                                                30    Is the death knell sounding for
                                                                                                                      traditional antivirus?



http://www.techrepublic.com/blog/datacenter/new-date-datatypes-in-sql-server-2008/443[08/29/2012 3:44:51 PM]
New Date Datatypes in SQL Server 2008 | TechRepublic




                                                                                                                   Start a Discussion

                    About Tim Chapman
                        Full Bio     Contact                                                                       Blog Archive

                                                                                                                     August 2012        December 2011
                                                                                                                     July 2012          November 2011
                                                                                                                     June 2012          October 2011
                   Options for passing a driver                 Restarting Active Directory
                                                                                                                     May 2012           September 2011
                   into the Windows Server                      as a service in Windows
                   2008 install program                         Server 2008                                          April 2012         August 2011
                                                                                                                     March 2012         July 2011
      People who read this...                                                                                        February 2012      June 2011
                                                                                                                     January 2012
          No change in SQL Server 2008 pricing, says Microsoft
          SQL server installation
          SQL Server 2008 - How to uninstall or Delete unused Multiple Instances
          10 tips for upgrading to SQL Server 2008 R2




         5            Join the conversation!                                             Add Your Opinion
      Comments        Follow via:



      Staff Picks      Top Rated      Most Recent      My Contacts                              See All Comments




                       Calendar issues                                                                0
                       rwilson@... 24th Feb 2009                                                    Votes



             Odd that it can go so far forward but not back far enough for some historical,
             geological, or anthropoligical data Actually, I was kind of wondering about the ability
             to go past 1753 with any... Read Whole Comment +


                 View in thread




                       Examples                                                                       0
                       chapman.tim@... 10th Sep 2008                                                Votes



             Sure, here are some examples:

             DATE:
             2007-05-08

             TIME:
             12:35:29. 1234567

             DATETIME2:
             2007-05-08 12:35:29. 1234567

             DATETIMEOFFSET:
             2007-05-08 12:35:29.1234567 +12:15


                 View in thread




http://www.techrepublic.com/blog/datacenter/new-date-datatypes-in-sql-server-2008/443[08/29/2012 3:44:51 PM]
New Date Datatypes in SQL Server 2008 | TechRepublic


                     RE: New Date Datatypes in SQL Server 2008                                        0
                     dwarsham@... 10th Sep 2008                                                     Votes



            Its about time we get a DATE type! I always tested date ranges like this: SELECT *
            FROM SalesHistory WHERE SaleDate Between @SaleDate AND @SaleDate + '
            11:59 pm' Of course @SaleDate was formatted... Read Whole Comment +


               View in thread




                                                See all comments



    Join the TechRepublic Community and join the conversation! Signing-up is
    free and quick, Do it now, we want to hear your opinion.

      Join       Login




http://www.techrepublic.com/blog/datacenter/new-date-datatypes-in-sql-server-2008/443[08/29/2012 3:44:51 PM]

Weitere ähnliche Inhalte

Ähnlich wie New date datatypes in sql server 2008 tech republic

introduction to datawarehouse
introduction to datawarehouseintroduction to datawarehouse
introduction to datawarehouse
kiran14360
 
Filtered indexes in sql server 2008 tech republic
Filtered indexes in sql server 2008   tech republicFiltered indexes in sql server 2008   tech republic
Filtered indexes in sql server 2008 tech republic
Kaing Menglieng
 
BizDataX White paper Test Data Management
BizDataX White paper Test Data ManagementBizDataX White paper Test Data Management
BizDataX White paper Test Data Management
Dragan Kinkela
 

Ähnlich wie New date datatypes in sql server 2008 tech republic (20)

introduction to datawarehouse
introduction to datawarehouseintroduction to datawarehouse
introduction to datawarehouse
 
WEBINAR - How Salesforce Service Cloud & DataArchiva has Helped Businesses Gr...
WEBINAR - How Salesforce Service Cloud & DataArchiva has Helped Businesses Gr...WEBINAR - How Salesforce Service Cloud & DataArchiva has Helped Businesses Gr...
WEBINAR - How Salesforce Service Cloud & DataArchiva has Helped Businesses Gr...
 
MS SQL SERVER: Microsoft time series algorithm
MS SQL SERVER: Microsoft time series algorithmMS SQL SERVER: Microsoft time series algorithm
MS SQL SERVER: Microsoft time series algorithm
 
MS SQL SERVER: Time series algorithm
MS SQL SERVER: Time series algorithmMS SQL SERVER: Time series algorithm
MS SQL SERVER: Time series algorithm
 
Filtered indexes in sql server 2008 tech republic
Filtered indexes in sql server 2008   tech republicFiltered indexes in sql server 2008   tech republic
Filtered indexes in sql server 2008 tech republic
 
SALES BASED DATA EXTRACTION FOR BUSINESS INTELLIGENCE
SALES BASED DATA EXTRACTION FOR BUSINESS INTELLIGENCESALES BASED DATA EXTRACTION FOR BUSINESS INTELLIGENCE
SALES BASED DATA EXTRACTION FOR BUSINESS INTELLIGENCE
 
DBT ELT approach for Advanced Analytics.pptx
DBT ELT approach for Advanced Analytics.pptxDBT ELT approach for Advanced Analytics.pptx
DBT ELT approach for Advanced Analytics.pptx
 
Tera stream ETL
Tera stream ETLTera stream ETL
Tera stream ETL
 
BizDataX White paper Test Data Management
BizDataX White paper Test Data ManagementBizDataX White paper Test Data Management
BizDataX White paper Test Data Management
 
Teradata Aggregate Join Indices And Dimensional Models
Teradata Aggregate Join Indices And Dimensional ModelsTeradata Aggregate Join Indices And Dimensional Models
Teradata Aggregate Join Indices And Dimensional Models
 
Partitioning your Oracle Data Warehouse - Just a simple task?
Partitioning your Oracle Data Warehouse - Just a simple task?Partitioning your Oracle Data Warehouse - Just a simple task?
Partitioning your Oracle Data Warehouse - Just a simple task?
 
Powerful Spatial Features You Never Knew Existed in Oracle Spatial and Graph ...
Powerful Spatial Features You Never Knew Existed in Oracle Spatial and Graph ...Powerful Spatial Features You Never Knew Existed in Oracle Spatial and Graph ...
Powerful Spatial Features You Never Knew Existed in Oracle Spatial and Graph ...
 
Sql server ___________session 2(sql 2008)
Sql server  ___________session 2(sql 2008)Sql server  ___________session 2(sql 2008)
Sql server ___________session 2(sql 2008)
 
SQL Server 2017 Community Driven Features
SQL Server 2017 Community Driven FeaturesSQL Server 2017 Community Driven Features
SQL Server 2017 Community Driven Features
 
Improve data engineering work with Digdag and Presto UDF
Improve data engineering work with Digdag and Presto UDFImprove data engineering work with Digdag and Presto UDF
Improve data engineering work with Digdag and Presto UDF
 
(OTW13) Agile Data Warehousing: Introduction to Data Vault Modeling
(OTW13) Agile Data Warehousing: Introduction to Data Vault Modeling(OTW13) Agile Data Warehousing: Introduction to Data Vault Modeling
(OTW13) Agile Data Warehousing: Introduction to Data Vault Modeling
 
Minería de Datos en Sql Server 2008
Minería de Datos en Sql Server 2008Minería de Datos en Sql Server 2008
Minería de Datos en Sql Server 2008
 
DataManagement_2015
DataManagement_2015DataManagement_2015
DataManagement_2015
 
An Overview of Data Lake
An Overview of Data LakeAn Overview of Data Lake
An Overview of Data Lake
 
Building the Enterprise Data Lake - Important Considerations Before You Jump In
Building the Enterprise Data Lake - Important Considerations Before You Jump InBuilding the Enterprise Data Lake - Important Considerations Before You Jump In
Building the Enterprise Data Lake - Important Considerations Before You Jump In
 

Mehr von Kaing Menglieng

What is your sql server backup strategy tech_republic
What is your sql server backup strategy    tech_republicWhat is your sql server backup strategy    tech_republic
What is your sql server backup strategy tech_republic
Kaing Menglieng
 
Using sql server 2008's merge statement tech republic
Using sql server 2008's merge statement   tech republicUsing sql server 2008's merge statement   tech republic
Using sql server 2008's merge statement tech republic
Kaing Menglieng
 
Using object dependencies in sql server 2008 tech republic
Using object dependencies in sql server 2008   tech republicUsing object dependencies in sql server 2008   tech republic
Using object dependencies in sql server 2008 tech republic
Kaing Menglieng
 
Using hash fields in sql server tech republic
Using hash fields in sql server   tech republicUsing hash fields in sql server   tech republic
Using hash fields in sql server tech republic
Kaing Menglieng
 
Using grouping sets in sql server 2008 tech republic
Using grouping sets in sql server 2008   tech republicUsing grouping sets in sql server 2008   tech republic
Using grouping sets in sql server 2008 tech republic
Kaing Menglieng
 
Understand when to use user defined functions in sql server tech-republic
Understand when to use user defined functions in sql server   tech-republicUnderstand when to use user defined functions in sql server   tech-republic
Understand when to use user defined functions in sql server tech-republic
Kaing Menglieng
 
Sql server indexed views speed up your select queries part 1 - code-projec
Sql server indexed views   speed up your select queries  part 1 - code-projecSql server indexed views   speed up your select queries  part 1 - code-projec
Sql server indexed views speed up your select queries part 1 - code-projec
Kaing Menglieng
 
Sql server – query optimization – remove bookmark lookup – remove rid lookup
Sql server – query optimization – remove bookmark lookup – remove rid lookupSql server – query optimization – remove bookmark lookup – remove rid lookup
Sql server – query optimization – remove bookmark lookup – remove rid lookup
Kaing Menglieng
 
Sql server common interview questions and answers
Sql server   common interview questions and answersSql server   common interview questions and answers
Sql server common interview questions and answers
Kaing Menglieng
 
Sql server common interview questions and answers page 6
Sql server   common interview questions and answers page 6Sql server   common interview questions and answers page 6
Sql server common interview questions and answers page 6
Kaing Menglieng
 
Sql server common interview questions and answers page 5
Sql server   common interview questions and answers page 5Sql server   common interview questions and answers page 5
Sql server common interview questions and answers page 5
Kaing Menglieng
 
Sql server common interview questions and answers page 4
Sql server   common interview questions and answers page 4Sql server   common interview questions and answers page 4
Sql server common interview questions and answers page 4
Kaing Menglieng
 
Sql server common interview questions and answers page 2
Sql server   common interview questions and answers page 2Sql server   common interview questions and answers page 2
Sql server common interview questions and answers page 2
Kaing Menglieng
 
Sql server – 2008 – hardware and software requirements for installing sql se
Sql server – 2008 – hardware and software requirements for installing sql seSql server – 2008 – hardware and software requirements for installing sql se
Sql server – 2008 – hardware and software requirements for installing sql se
Kaing Menglieng
 
Speeding up queries with semi joins and anti-joins
Speeding up queries with semi joins and anti-joinsSpeeding up queries with semi joins and anti-joins
Speeding up queries with semi joins and anti-joins
Kaing Menglieng
 
Speed up sql server apps - visual studio magazine
Speed up sql server apps  - visual studio magazineSpeed up sql server apps  - visual studio magazine
Speed up sql server apps - visual studio magazine
Kaing Menglieng
 
See sql server graphical execution plans in action tech republic
See sql server graphical execution plans in action   tech republicSee sql server graphical execution plans in action   tech republic
See sql server graphical execution plans in action tech republic
Kaing Menglieng
 
Reviewing sql server permissions tech republic
Reviewing sql server permissions   tech republicReviewing sql server permissions   tech republic
Reviewing sql server permissions tech republic
Kaing Menglieng
 
Query optimization how to search millions of record in sql table faster -
Query optimization   how to search millions of record in sql table faster  -Query optimization   how to search millions of record in sql table faster  -
Query optimization how to search millions of record in sql table faster -
Kaing Menglieng
 

Mehr von Kaing Menglieng (20)

What is your sql server backup strategy tech_republic
What is your sql server backup strategy    tech_republicWhat is your sql server backup strategy    tech_republic
What is your sql server backup strategy tech_republic
 
Using sql server 2008's merge statement tech republic
Using sql server 2008's merge statement   tech republicUsing sql server 2008's merge statement   tech republic
Using sql server 2008's merge statement tech republic
 
Using object dependencies in sql server 2008 tech republic
Using object dependencies in sql server 2008   tech republicUsing object dependencies in sql server 2008   tech republic
Using object dependencies in sql server 2008 tech republic
 
Using hash fields in sql server tech republic
Using hash fields in sql server   tech republicUsing hash fields in sql server   tech republic
Using hash fields in sql server tech republic
 
Using grouping sets in sql server 2008 tech republic
Using grouping sets in sql server 2008   tech republicUsing grouping sets in sql server 2008   tech republic
Using grouping sets in sql server 2008 tech republic
 
Understand when to use user defined functions in sql server tech-republic
Understand when to use user defined functions in sql server   tech-republicUnderstand when to use user defined functions in sql server   tech-republic
Understand when to use user defined functions in sql server tech-republic
 
Sql server indexed views speed up your select queries part 1 - code-projec
Sql server indexed views   speed up your select queries  part 1 - code-projecSql server indexed views   speed up your select queries  part 1 - code-projec
Sql server indexed views speed up your select queries part 1 - code-projec
 
Sql server – query optimization – remove bookmark lookup – remove rid lookup
Sql server – query optimization – remove bookmark lookup – remove rid lookupSql server – query optimization – remove bookmark lookup – remove rid lookup
Sql server – query optimization – remove bookmark lookup – remove rid lookup
 
Sql server common interview questions and answers
Sql server   common interview questions and answersSql server   common interview questions and answers
Sql server common interview questions and answers
 
Sql server common interview questions and answers page 6
Sql server   common interview questions and answers page 6Sql server   common interview questions and answers page 6
Sql server common interview questions and answers page 6
 
Sql server common interview questions and answers page 5
Sql server   common interview questions and answers page 5Sql server   common interview questions and answers page 5
Sql server common interview questions and answers page 5
 
Sql server common interview questions and answers page 4
Sql server   common interview questions and answers page 4Sql server   common interview questions and answers page 4
Sql server common interview questions and answers page 4
 
Sql server common interview questions and answers page 2
Sql server   common interview questions and answers page 2Sql server   common interview questions and answers page 2
Sql server common interview questions and answers page 2
 
Sql server – 2008 – hardware and software requirements for installing sql se
Sql server – 2008 – hardware and software requirements for installing sql seSql server – 2008 – hardware and software requirements for installing sql se
Sql server – 2008 – hardware and software requirements for installing sql se
 
Speeding up queries with semi joins and anti-joins
Speeding up queries with semi joins and anti-joinsSpeeding up queries with semi joins and anti-joins
Speeding up queries with semi joins and anti-joins
 
Speed up sql
Speed up sqlSpeed up sql
Speed up sql
 
Speed up sql server apps - visual studio magazine
Speed up sql server apps  - visual studio magazineSpeed up sql server apps  - visual studio magazine
Speed up sql server apps - visual studio magazine
 
See sql server graphical execution plans in action tech republic
See sql server graphical execution plans in action   tech republicSee sql server graphical execution plans in action   tech republic
See sql server graphical execution plans in action tech republic
 
Reviewing sql server permissions tech republic
Reviewing sql server permissions   tech republicReviewing sql server permissions   tech republic
Reviewing sql server permissions tech republic
 
Query optimization how to search millions of record in sql table faster -
Query optimization   how to search millions of record in sql table faster  -Query optimization   how to search millions of record in sql table faster  -
Query optimization how to search millions of record in sql table faster -
 

New date datatypes in sql server 2008 tech republic

  • 1. New Date Datatypes in SQL Server 2008 | TechRepublic ZDNet Asia SmartPlanet TechRepublic Log In Join TechRepublic FAQ Go Pro! Blogs Downloads Newsletters Galleries Q&A Discussions News Research Library IT Management Development IT Support Data Center Networks Security Home / Blogs / The Enterprise Cloud Follow this blog: The Enterprise Cloud New Date Datatypes in SQL Server 2008 By Tim Chapman September 8, 2008, 10:59 AM PDT Takeaway: SQL Server 2008 provides new data-types for storing wider ranges of dates with more precision. Heres can you can use these new data types to your advantage in SQL Server 2008. As a database architect, one of the features I am most excited about in SQL Server 2008 is the new date related data types. These data types allow for the storage of time-only data, date-only data, a larger range of date values, more time precision, and the ability to store time-zone specific dates. Today I’ll take a look at these great new data types and how they can be used to expand Btrieve 6.15 Forever your date storage possibilities. Still using Btrieve? So are we! Get the Ultimate DATE Btrieve Patch pervasivedb.com/btrieve The new DATE data-type defines a date field without any associated time. In previous versions of Improve Productivity SQL Server, storing time-only data was accomplished in one of two ways. First, you could define Apps For Business- 30 Day Free Trial. No either a DATETIME or SMALLDATETIME data type and assign the value as a VARCHAR value. Credit Card Required! Then you would need to handle the time related data in your queries. The other way is to store the www.google.com/apps date value in a VARCHAR field in the database. Either way, handling date-only data was at best OTM (G-Log) Solutions cumbersome. With the new DATE data-type, it intrinsically stores only date values. In the following At MavenWire, We Offer Solutions to Meet example I define a DATE data-type and a DATETIME data type and assign today’s date to the Your Business Needs. Visit Us! variables. As you can see from SELECTing the values from the variables, the DATE variable holds www.MavenWire.com only the date portion whereas the DATETIME field also stores the associated time from the GETDATE() function. DECLARE @TodaysDate DATE = GETDATE() DECLARE @TodaysDateTime DATETIME = GETDATE() Keep Up with TechRepublic SELECT @TodaysDate, @TodaysDateTime Storing DATE specific data will also make queries easier to write. Instead of using one of the following statements to pull data for a DATETIME column; Five Apps SELECT * FROM SalesHistory Google in the Enterprise WHERE SaleDate = ‘4/11/2008' AND SaleDate ‘4/12/2008' you can use an equality operator (=) to search only for the specific date, assuming the Subscribe Today SaleDateOnly field is defined as a DATE data-type. SELECT * FROM SalesHistory Follow us however you choose! WHERE SaleDateOnly = ‘4/11/2008' http://www.techrepublic.com/blog/datacenter/new-date-datatypes-in-sql-server-2008/443[08/29/2012 3:44:51 PM]
  • 2. New Date Datatypes in SQL Server 2008 | TechRepublic DATETIME2 This data type is very simiilar to the datetime data type present in previous versions of SQL Server. The difference is the time precision and the range of dates that DATETIME2 can store. The new DATETIME2 data type can hold a range of dates from 0001-01-01 through 9999-12-31 while DATETIME holds the date range from 1753-01-01 to 9999-12-31. Another benefit of this Media Gallery data type is the precision in which it records time. DATETIME2 is accurate to within 100 nanoseconds whereas DATETIME is accurate to within 3/1000 of a second. The following script compares the values that the DATETIME and the DATETIME2 data-types can hold. DECLARE @DateTime2 DATETIME2 = GETDATE() DECLARE @DateTime DATETIME = GETDATE() PHOTO GALLERY (1 of 15) SELECT @DateTime, @DateTime2 Curiosity's autonomous 'seven minutes of... Notice the additional precision stored in the DATETIME2 variable. This additional data can be of More Galleries » major significance for those applications where time related information is mission-critical. TIME The TIME data-type stores only the time portion of a date. This is significant in that the time data can be stored seperately and not associated with a specific date. The TIME data-type, like the DATETIME2 data-type is accurate up to 100 nanoseconds. The following script compares the time specific information returned by the TIME data type and that which is returned from a DATETIME VIDEO (1 of 13) data type. Cracking Open: HTC Titan II DECLARE @Time TIME = GETDATE() More Videos » DECLARE @DateTime DATETIME = GETDATE() SELECT @Time, @DateTime Hot Questions View All DATETIMEOFFSET 3 SSL redirection The new DATETIMEOFFSET data type combines the range and precision of the DATETIME2 data-type along with time-zone awareness based on a 24 hour clock. The time-zone awareness is accomplished by adding or subtracting an hours + minutes value to the date data. In the following example, I define a temporary table that holds two fields. The first field holds the date that is local 2 can anyone suggest if any such to my area. The second field, BeijingTime, is an offset date that will hold the time in Beijing, China; software exist with similar which happens to be 12 hours ahead of the time in Louisville, KY. functionality? CREATE TABLE #OffSets 3 Switching from a Job to a career in ( the IT field: Need an IT pro's LouisvilleTime DATETIME2 DEFAULT(GETDATE()), advice BeijingTime AS CONVERT(VARCHAR(50), LouisvilleTime, 121) + '+12:00' 2 windows 7 won't shutdown and ) keeps switching on INSERT INTO #OffSets(LouisvilleTime) SELECT GETDATE() Ask a Question SELECT * FROM #OffSets As you can see from the results from the table, the BeijingTime field holds the date from the LouisvilleTime field along with a 12 hour offset to indicate Beijing time. This data-type greatly Hot Discussions View All enhances the ability to create time-zone aware applications. 221 Should developers be sued for TIME to try the new data-types security holes? The new date related data-types included in SQL Server 2008 greatly expand the database developers ability to not only store a wider range of dates and precision for those dates, but also 79 The sitting duck that is open the ability to zone time-zone specific data which can lead to more robust and accurate reporting of source time-related data around the world. 27 Five fast Windows desktop search utilities Get IT Tips, news, and reviews delivered directly to your inbox by subscribing to TechRepublic’s free newsletters. 30 Is the death knell sounding for traditional antivirus? http://www.techrepublic.com/blog/datacenter/new-date-datatypes-in-sql-server-2008/443[08/29/2012 3:44:51 PM]
  • 3. New Date Datatypes in SQL Server 2008 | TechRepublic Start a Discussion About Tim Chapman Full Bio Contact Blog Archive August 2012 December 2011 July 2012 November 2011 June 2012 October 2011 Options for passing a driver Restarting Active Directory May 2012 September 2011 into the Windows Server as a service in Windows 2008 install program Server 2008 April 2012 August 2011 March 2012 July 2011 People who read this... February 2012 June 2011 January 2012 No change in SQL Server 2008 pricing, says Microsoft SQL server installation SQL Server 2008 - How to uninstall or Delete unused Multiple Instances 10 tips for upgrading to SQL Server 2008 R2 5 Join the conversation! Add Your Opinion Comments Follow via: Staff Picks Top Rated Most Recent My Contacts See All Comments Calendar issues 0 rwilson@... 24th Feb 2009 Votes Odd that it can go so far forward but not back far enough for some historical, geological, or anthropoligical data Actually, I was kind of wondering about the ability to go past 1753 with any... Read Whole Comment + View in thread Examples 0 chapman.tim@... 10th Sep 2008 Votes Sure, here are some examples: DATE: 2007-05-08 TIME: 12:35:29. 1234567 DATETIME2: 2007-05-08 12:35:29. 1234567 DATETIMEOFFSET: 2007-05-08 12:35:29.1234567 +12:15 View in thread http://www.techrepublic.com/blog/datacenter/new-date-datatypes-in-sql-server-2008/443[08/29/2012 3:44:51 PM]
  • 4. New Date Datatypes in SQL Server 2008 | TechRepublic RE: New Date Datatypes in SQL Server 2008 0 dwarsham@... 10th Sep 2008 Votes Its about time we get a DATE type! I always tested date ranges like this: SELECT * FROM SalesHistory WHERE SaleDate Between @SaleDate AND @SaleDate + ' 11:59 pm' Of course @SaleDate was formatted... Read Whole Comment + View in thread See all comments Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion. Join Login http://www.techrepublic.com/blog/datacenter/new-date-datatypes-in-sql-server-2008/443[08/29/2012 3:44:51 PM]