- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
Using DATE, TIME, and DATETIME2 in Font
Using DATE, TIME, and DATETIME2 Make PDF 417 In None Using Barcode generator for Font Control to generate, create PDF417 image in Font applications. www.OnBarcode.comPrinting EAN 128 In None Using Barcode creator for Font Control to generate, create GS1 128 image in Font applications. www.OnBarcode.comYou can store just a date or time value by using the new DATE and TIME data types. The traditional DATETIME and SMALLDATETIME data types default to 12 a.m. when you do not specify the time. You can also specify a precision, from zero to seven decimal places, when using the TIME and DATETIME2 data types. Type in and execute Listing 9-6 to learn how to use the new types. UPC A Maker In None Using Barcode encoder for Font Control to generate, create UPC Symbol image in Font applications. www.OnBarcode.comCode 39 Printer In None Using Barcode drawer for Font Control to generate, create Code 3/9 image in Font applications. www.OnBarcode.comCHAPTER 9 WORKING WITH NEW DATA TYPES
Drawing PDF 417 In None Using Barcode generation for Font Control to generate, create PDF 417 image in Font applications. www.OnBarcode.comMake ECC200 In None Using Barcode creation for Font Control to generate, create DataMatrix image in Font applications. www.OnBarcode.comListing 9-6. Using DATE and TIME USE tempdb; --1 IF OBJECT_ID('dbo.DateDemo') IS NOT NULL BEGIN DROP TABLE dbo.DateDemo; END GO --2 CREATE TABLE dbo.DateDemo(JustTheDate DATE, JustTheTime TIME(1), NewDateTime2 DATETIME2(3), UTCDate DATETIME2); GO --3 INSERT INTO dbo.DateDemo (JustTheDate, JustTheTime, NewDateTime2, UTCDate) VALUES (SYSDATETIME(), SYSDATETIME(), SYSDATETIME(), SYSUTCDATETIME()); --4 SELECT JustTheDate, JustTheTime, NewDateTime2, UTCDate FROM dbo.DateDemo; Figure 9-9 shows the results. Code section 1 drops the dbo.DateDemo table if it already exists. Statement 2 creates the dbo.DateDemo table with a DATE, a TIME, and two DATETIME2 columns. Notice that the TIME and DATETIME2 columns have the precision specified. The default is seven places if a precision is not specified. Statement 3 inserts a row into the table using the new SYSDATETIME function. This function works like the GETDATE function except that it has greater precision than GETDATE. The statement populates the UTCDate column with the SYSUTCDATETIME function, which provides the Coordinated Universal Time (UTC). Statement 4 shows the results. The JustTheDate value shows that even though the SYSDATETIME function populated it, it stored only the date. The JustTheTime values stored only the time with one decimal place past the seconds. The NewDateTime2 column stored both the date and time with three decimal places. The UTCDate column stored the UTC date along with seven decimal places. Since the computer running this demo is in Central time, the time is five hours different. EAN-13 Maker In None Using Barcode maker for Font Control to generate, create GTIN - 13 image in Font applications. www.OnBarcode.comDrawing UPC - E0 In None Using Barcode drawer for Font Control to generate, create UPC-E Supplement 2 image in Font applications. www.OnBarcode.comFigure 9-9. The results of using the new date and time data types
PDF-417 2d Barcode Maker In Visual Studio .NET Using Barcode maker for Reporting Service Control to generate, create PDF-417 2d barcode image in Reporting Service applications. www.OnBarcode.comPDF417 Printer In None Using Barcode printer for Microsoft Word Control to generate, create PDF417 image in Word applications. www.OnBarcode.comCHAPTER 9 WORKING WITH NEW DATA TYPES
Draw Barcode In Visual Studio .NET Using Barcode maker for Reporting Service Control to generate, create Barcode image in Reporting Service applications. www.OnBarcode.comEAN13 Creator In VS .NET Using Barcode drawer for ASP.NET Control to generate, create EAN-13 image in ASP.NET applications. www.OnBarcode.comOne issue I have seen with these new data types is that running SQL Server on Vista 64-bit does not record all the decimal places with the new data types and fills in with zeros after three places. You will see better results when running SQL Server on different operating systems. Most business applications will not require the default precision of seven places found with the TIME and DATETIME2 types. Be sure to specify the required precision when creating tables with columns of these types to save space in your database. Read Barcode In .NET Using Barcode scanner for .NET framework Control to read, scan read, scan image in .NET applications. www.OnBarcode.comPaint Data Matrix In C#.NET Using Barcode encoder for .NET Control to generate, create DataMatrix image in VS .NET applications. www.OnBarcode.comUsing DATETIMEOFFSET
Barcode Creation In None Using Barcode printer for Software Control to generate, create Barcode image in Software applications. www.OnBarcode.comPrint GS1 - 13 In Java Using Barcode creation for Java Control to generate, create GTIN - 13 image in Java applications. www.OnBarcode.comThe new DATETIMEOFFSET data type contains, in addition to the date and time, a time zone offset for working with dates and times in different time zones. This is the difference between the UTC date and time and the stored date. Along with the new data type, several new functions for working with DATETIMEOFFSET are available. Type in and execute Listing 9-7 to learn how to work with this new data type. Listing 9-7. Using the DATETIMEOFFSET Data Type USE tempdb; --1 IF OBJECT_ID('dbo.OffsetDemo') IS NOT NULL BEGIN DROP TABLE dbo.OffsetDemo; END; --2 CREATE TABLE dbo.OffsetDemo(Date1 DATETIMEOFFSET); GO --3 INSERT INTO dbo.OffsetDemo(Date1) VALUES (SYSDATETIMEOFFSET()), (SWITCHOFFSET(SYSDATETIMEOFFSET(),'+00:00')), (TODATETIMEOFFSET(SYSDATETIME(),'+05:00')) Code 3/9 Creation In VS .NET Using Barcode printer for ASP.NET Control to generate, create Code 39 Extended image in ASP.NET applications. www.OnBarcode.comDecoding UPC Symbol In .NET Using Barcode decoder for .NET framework Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.com--4 SELECT Date1 FROM dbo.OffsetDemo; Figure 9-10 shows the results. Code section 1 drops the dbo.OffsetDemo table if it exists. Statement 2 creates the table with a DATETIMEOFFSET column, Date1. Statement 3 inserts three rows into the table using the new functions for working with the new data types. The SYSDATETIMEOFFSET function returns the date and time on the server along with the time zone offset. The computer I am using is five hours behind UTC, so the value 05:00 appears after the current date and time. Using the SWITCHOFFSET function, you can switch a DATETIMEOFFSET value to another time zone. Notice that by switching to Painting Barcode In Objective-C Using Barcode printer for iPad Control to generate, create Barcode image in iPad applications. www.OnBarcode.comPrint PDF-417 2d Barcode In Java Using Barcode drawer for Java Control to generate, create PDF417 image in Java applications. www.OnBarcode.com |
|