- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
Potential Values for datepart in Font
Table 11-1. Potential Values for datepart PDF-417 2d Barcode Encoder In None Using Barcode generator for Font Control to generate, create PDF417 image in Font applications. www.OnBarcode.comEncode EAN / UCC - 14 In None Using Barcode creation for Font Control to generate, create EAN / UCC - 14 image in Font applications. www.OnBarcode.comdatepart Definition
Encoding ECC200 In None Using Barcode encoder for Font Control to generate, create ECC200 image in Font applications. www.OnBarcode.comPaint UCC - 12 In None Using Barcode creator for Font Control to generate, create UPC Symbol image in Font applications. www.OnBarcode.comisowk, isoww
Drawing Barcode In None Using Barcode creator for Font Control to generate, create Barcode image in Font applications. www.OnBarcode.comEuropean Article Number 13 Generation In None Using Barcode generation for Font Control to generate, create EAN / UCC - 13 image in Font applications. www.OnBarcode.comMeaning
Barcode Generation In None Using Barcode creation for Font Control to generate, create Barcode image in Font applications. www.OnBarcode.comUSPS Confirm Service Barcode Creator In None Using Barcode generation for Font Control to generate, create USPS PLANET Barcode image in Font applications. www.OnBarcode.comISOWeek is a numbering system used to give every week in the calendar a unique, ascending number. An ISO week starts on a Monday, and Week 1 is the week containing the first Thursday of that year. For example, in 2008, the first Thursday occurred on January 3, so Week 1 ran from December 31, 2007, through January 6, 2008. Timezone offset Nanosecond Microsecond Millisecond Second Minute Hour Weekday Week Day Day of year Month Quarter Year Creating PDF 417 In Java Using Barcode maker for BIRT Control to generate, create PDF-417 2d barcode image in BIRT reports applications. www.OnBarcode.comPDF-417 2d Barcode Generation In None Using Barcode creation for Font Control to generate, create PDF 417 image in Font applications. www.OnBarcode.comtz ns mcs ms ss, s mi, n hh dw, w wk, ww dd, d dy, y mm, n qq, q yy, yyyy
Making QR-Code In Objective-C Using Barcode creator for iPhone Control to generate, create QR Code 2d barcode image in iPhone applications. www.OnBarcode.comCreating DataMatrix In Visual Studio .NET Using Barcode drawer for Reporting Service Control to generate, create DataMatrix image in Reporting Service applications. www.OnBarcode.comTaking the second option of the datepart function, to add the value, make the number positive, and to subtract a number, make it negative. Moving to the final option of the datepart function, this can be either a value, a variable, or a column date type holding the date and time you wish to change. UCC - 12 Encoder In Java Using Barcode encoder for BIRT Control to generate, create UCC - 12 image in BIRT reports applications. www.OnBarcode.comPrinting EAN13 In Java Using Barcode maker for Java Control to generate, create EAN13 image in Java applications. www.OnBarcode.comCHAPTER 11 T-SQL ESSENTIALS
Painting EAN / UCC - 13 In Java Using Barcode encoder for Java Control to generate, create EAN / UCC - 13 image in Java applications. www.OnBarcode.com2D Barcode Drawer In VB.NET Using Barcode generation for .NET framework Control to generate, create 2D image in Visual Studio .NET applications. www.OnBarcode.comTry It Out: DATEADD() Read GS1 128 In C# Using Barcode scanner for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comUPC Symbol Encoder In None Using Barcode creation for Software Control to generate, create UPC A image in Software applications. www.OnBarcode.com1. We will set a local variable to a date and time. After that, we will add four hours to the value and display the results, as shown in Figure 11-20. DECLARE @OldTime datetime SET @OldTime = '24 March 2008 3:00 PM' SELECT DATEADD(hh,4,@OldTime) Painting Barcode In .NET Using Barcode creation for ASP.NET Control to generate, create Barcode image in ASP.NET applications. www.OnBarcode.comBarcode Drawer In VB.NET Using Barcode drawer for .NET Control to generate, create Barcode image in VS .NET applications. www.OnBarcode.comFigure 11-20. Adding hours to a date 2. Taking the reverse, we will take the same variable and remove six hours. The results should appear as shown in Figure 11-21. DECLARE @OldTime datetime SET @OldTime = '24 March 2008 3:00 PM' SELECT DATEADD(hh,-6,@OldTime) Figure 11-21. Subtracting hours from a date
DATEDIFF() To find the difference between two dates, you would use the function DATEDIFF(). The syntax for this function is DATEDIFF(datepart, startdate, enddate) The first option contains the same options as for DATEADD(), and startdate and enddate are the two days you wish to compare. A negative number shows that the enddate is before the startdate. Try It Out: DATEDIFF() We will set two local variables to a date and time. After that, we find the difference in milliseconds. DECLARE @FirstTime datetime, @SecondTime datetime SET @FirstTime = '24 March 2008 3:00 PM' SET @SecondTime = '24 March 2008 3:33PM' SELECT DATEDIFF(ms,@FirstTime,@SecondTime) CH A PT ER 1 1 T -SQ L ES SEN TI ALS
Figure 11-22 shows the results after executing this code.
Figure 11-22. The difference between two dates
DATENAME() Returning the name of the part of the date is great for using with things such as customer statements. Changing the number 6 to the word June makes for more pleasant reading. The syntax is DATENAME(datepart, datetoinspect) We will also see this in action in DATEPART(). Try It Out: DATENAME() In this example, we will set one date and time and then return the day of the week. We know this to be a Monday. DECLARE @StatementDate datetime SET @StatementDate = '24 March 2008 3:00 PM' SELECT DATENAME(dw,@StatementDate) Figure 11-23 shows the results after executing this code. Figure 11-23. The day name of a date
DATEPART() If you wish to achieve returning part of a date from a date variable, column, or value, you can use DATEPART() within a SELECT statement. As you may be expecting by now, the syntax has datepart as the first option, and then the datetoinspect as the second option, which returns the numerical day of the week from the date inspected. DATEPART(datepart, datetoinspect) CHAPTER 11 T-SQL ESSENTIALS
Try It Out: DATEPART() 1. We need to set only one local variable to a date and time. After that, we find the day of the month. DECLARE @WhatsTheDay datetime SET @WhatsTheDay = '24 March 2008 3:00 PM' SELECT DATEPART(dd, @WhatsTheDay) Figure 11-24 shows the results after executing this code. Figure 11-24. Finding part of a date 2. To produce a more pleasing date and time for a statement, we can combine DATEPART() and DATENAME() to have a meaningful output. The function CAST(), which we will look at in detail shortly, is needed here, as it is a data type conversion function. DECLARE @WhatsTheDay datetime SET @WhatsTheDay = '24 March 2008 3:00 PM' SELECT DATENAME(dw, @WhatsTheDay) + ', ' + CAST(DATEPART(dd,@WhatsTheDay) AS varchar(2)) + ' ' + DATENAME(mm,@WhatsTheDay) + ' ' + CAST(DATEPART(yyyy,@WhatsTheDay) AS char(4)) 3. When this is executed, it will produce the more meaningful date shown in Figure 11-25.
|
|