Mega Code Archive
Search
.Net
ASP .Net
ASP .Net Tutorial
C#
C# Book
C# by API
C# Tutorial
VB.Net
VB.Net by API
VB.Net Tutorial
Visual C++ .Net
VisualBasic Script
Java
Java
Java Book
Java by API
Java Tutorial
Script
Flash ActionScript
Flex
JavaScript DHTML
JavaScript Reference
JavaScript Tutorial
Database
MSSQL
MSSQL Tutorial
MySQL
MySQL Tutorial
Oracle PLSQL
Oracle PLSQL Tutorial
PostgreSQL
Languages
Android
C
C Tutorial
C++
C++ Tutorial
Delphi
Perl
PHP
Python
Python Tutorial
Ruby
Silverlight
Office
MSOfficeExcel 2007 Tutorial
MSOfficePowerPoint 2007 Tutorial
MSOfficeWord 2007 Tutorial
Data
XML
XML Tutorial
MSSQL Tutorial
Date Functions 98 codes
Home
MSSQL Tutorial
Date Functions
1 (DATEPART(dd, @date1) = DATEPART(dd, @date2))
2 (DATEPART(mm, @date1) = DATEPART(mm, @date2))
3 (DATEPART(yy, @date1) = DATEPART(yy, @date2)
4 A SELECT statement that computes the age of a Billing with DATEDIFF
5 A statement that changes the date format
6 Calculating the First Day of the Month
7 CHECK (entered_date = CURRENT_TIMESTAMP)
8 Combining this with DATEADD allows you to find out the month name in two months time
9 CONVERT(varchar,GETDATE(),113) dd Mmm yyyy hh
10 DATEADD adds a time interval to a date in order to arrive at the new date
11 DATEADD adds or subtract a number of days, months, or years from a specific date
12 DATEDIFF returns the difference between two dates as specified by datepart
13 DATENAME returns dates character string representation
14 DATEPART Function returns the integer value of the datepart specified
15 DATEPART returns part of a date as an integer value
16 Datetime DEFAULT CURRENT_TIMESTAMP
17 Days between two dates
18 Determine the date 90 days after April 29, 1988
19 Displaying the Integer Value For Part of a Date using DAY
20 Displaying the Integer Value For Part of a Date using MONTH
21 Displaying the Integer Value For Part of a Date using YEAR
22 Displaying the String Value for Part of a Date
23 Find difference in months between now and EndDate
24 Finding the Difference Between Two Dates
25 Finding the Last Day of the Month
26 GETDATE function returns the current system date and time of the server
27 Grouping by the Week by using datepart function
28 Identifying Weekday
29 IF DATEDIFF(dd, 7599,7500) = 0
30 Make sure month and day are two char long and build the date string
31 Returning the Current Date and Time GETUTCDATE()
32 SELECT @today = current_timestamp
33 Select CONVERT(varchar,GETDATE(),108) hh
34 Select CONVERT(varchar,GETDATE(),114) hh
35 Select CURRENT_TIMESTAMP
36 Select DATEADD(day, 1, 2002-09-30 11
37 SELECT DATEADD(day, 14, GETDATE())
38 Select DATEADD(hour, 1, 2002-09-30 11
39 Select DATEADD(minute, 1, 2002-09-30 11
40 Select DATEADD(month, -1, 2002-09-30 11
41 Select DATEADD(month, 1, 2002-09-30 11
42 Select DATEADD(quarter, 1, 2002-09-30 11
43 Select DATEADD(second, 1, 2002-09-30 11
44 Select DATEADD(week, 1, 2002-09-30 11
45 Select DATEADD(year, 1 5, 2002-09-30 11
46 Select DATEADD(year, 1, 2002-09-30 11
47 Select DATEDIFF(day, 2001-12-01, 2002-09-30)
48 Select DATEDIFF(day, 2002-09-30, 2001-12-01)
49 Select DATEDIFF(hour, 06
50 Select DATEDIFF(minute, 06
51 Select DATEDIFF(month, 2001-12-01, 2002-09-30)
52 Select DATEDIFF(quarter, 2001-12-01, 2002-09-30)
53 Select DATEDIFF(second, 06
54 Select DATEDIFF(week, 2001-12-01, 2002-09-30)
55 Select DATEDIFF(year, 2001-12-01, 2002-09-30)
56 SELECT DATEDIFF(yy, Dec 31, 1998, Jan 1, 1999)
57 SELECT DATEDIFF(yy, Jan 1, 1998, Dec 31, 1998)
58 Select DATENAME(day, 2002-09-30 11
59 Select DATENAME(dayofyear, 2002-09-30 11
60 Select DATENAME(hour, 2002-09-30 11
61 Select DATENAME(minute, 2002-09-30 11
62 Select DATENAME(month, 2002-09-30 11
63 Select DATENAME(month,2002-09-30)
64 Select DATENAME(quarter, 2002-09-30 11
65 Select DATENAME(second, 2002-09-30 11
66 Select DATENAME(week, 2002-09-30 11
67 Select DATENAME(weekday, 2002-09-30 11
68 Select DATENAME(year, 2002-09-30 11
69 Select DATEPART(day, 2002-09-30 11
70 Select DATEPART(dayofyear, 2002-09-30 11
71 SELECT DATEPART(dd, 7500)
72 SELECT DATEPART(dd, 7599)
73 Select DATEPART(hour, 2002-09-30 11
74 Select DATEPART(m,2002-09-30)
75 Select DATEPART(minute, 2002-09-30 11
76 Select DATEPART(month, 2002-09-30 11
77 Select DATEPART(quarter, 2002-09-30 11
78 Select DATEPART(second, 2002-09-30 11
79 Select DATEPART(week, 2002-09-30 11
80 Select DATEPART(weekday, 2002-09-30 11
81 SELECT DATEPART(weekday, CAST(20051004 AS DATETIME) + @@DATEFIRST)
82 Select DATEPART(year, 2002-09-30 11
83 Select DAY(2002-09-30)
84 Select GETDATE()
85 SELECT GETDATE() + 14
86 Select ISDATE(2002-09-30)
87 Select ISDATE(2002-09-31)
88 Select ISDATE(23
89 Select MONTH(2002-09-30)
90 Select YEAR(2002-09-30)
91 To change the first day value, you can use the SET DATEFIRST command
92 Use GetDate() function in where clause
93 Using SQL Servers First Day of the Week Setting
94 Values for the datepart parameter
95 Where DATEDIFF(WEEK, pubdate, GETDATE()) = 48
96 Where DATEPART(DAY, pubdate) BETWEEN 8 AND 14
97 WHERE DATEPART(WEEKDAY, pubdate) = 3
98 YEAR, MONTH, DAY