Professional Documents
Culture Documents
Chapter 6
Chapter 6
Single-Row Functions(2)
Objectives
Display
Access
Perform calculation with Dates
Using Dates and Conversion functions
Understand NULL values
Change the display of dates, number
and text
Time()
Now()
Current Time
9:15:40 PM
LastName
Lee
DateEnrolled
05-Jan-02
New Date
2/4/2002
Week in School
Bartell
204.714285714286
Mikulski
122.714285714286
Tham
121.714285714286
Williams
161.857142857143
Dates Functions
Function Name
Description
Day(date)
Month(date)
Year(date)
Weekday(date)
Output:
Year Enrolled
No of years in schools
2002
2001
2001
2000
Month Enrolled
Sixth Month
S003
S005
10
S011
10
S013
DateEnrolled
Date
S003
05-Jan-02
S005
01-Apr-01
S011
01-Apr-01
S013
30-Mar-00
30
DateEnrolled
Day of Week
S003
05-Jan-02
S005
01-Apr-01
S011
01-Apr-01
S013
30-Mar-00
Interval value
The interval value for both DateAdd and DateDiff functions is the
same.
The interval is the argument to instructs the function what kind of
setting you want to add/subtract to the date.
Setting
Description
Day
Month
yyyy
Year
weekday
ww
week
Hour
Minute
second
DateAdd Functions
Allow
DateEnrolled
Add 6 months
Add 5 weekdays
S003
05-Jan-02
7/5/2002
1/10/2002
S005
01-Apr-01
10/1/2001
4/6/2001
S011
01-Apr-01
10/1/2001
4/6/2001
S013
30-Mar-00
9/30/2000
4/4/2000
DateDiff Functions
Allow
date1, date2)
If date1 > date 2, result will be in negative
value.
DateEnrolled
Year
S003
05-Jan-02
S005
01-Apr-01
S011
01-Apr-01
S013
30-Mar-00
Conversion Function
Function Name
Description
CDate(expr)
CInt(expr)
CStr(expr)
Nz(expr, value)
LastName
DateEnrolled
S001
Bartell
15-Feb-02
S003
Lee
05-Jan-02
S006
Mikulski
12-Sep-03
S007
Tham
19-Sep-03
S009
Nicosia
01-Feb-02
S012
Maser
25-Sep-03
S014
Williams
12-Dec-02
S015
Chan
12-Dec-02
LastName
Total Points
Bartell
25.68
Kebel
21.68
Lee
30.56
null
Lewis
.
NZ function
NZ
NZ (expression, value).
expression is the source of the data, column or
expression that may contain null
value is the target value for converting null.
Both
Using NZ function
SELECT Student. LastName, NZ(GPA,0)*8 AS [Total Points]
FROM Student;
Output:
LastName
Total Points
Bartell
25.68
Kebel
21.68
Lee
30.56
Lewis
Law
24.4
..
..
Roche
15.04
Williams
21.92
Chan
24.96
Jann
Formatting in Access
You
Description
Full year (0100 to 9999).
yy
mmmm
mmm
mm
dd
ddd
dddd
12-31-2005 07:36 PM
dd-mmm-yy
31-Dec-05
mm-dd-yyyy
12-31-2005
hh:nn:ss am/pm
07:36:45 PM
hh:nn am/pm
07:36 PM
hh:nn
19:36
LastName
Expr1002
S001
Bartell
S003
Lee
S006
Mikulski
S007
Tham
S009
Nicosia
S012
Maser
S014
Williams
S015
Chan
Description
. (period)
Decimal separator.
, (comma)
Thousand separator.
4,234.00
$2,000.00
800.00%
Description
&
<
>
Name
Bartell
BARTELL
Mikulski
MIKULSKI
Tham
THAM
Williams
WILLIAMS
Summary
Use date and conversion functions to:
Convert