• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
AIN102D Access date functions sample queries
 

AIN102D Access date functions sample queries

on

  • 1,022 views

Example queries of every date function in Microsoft Access.

Example queries of every date function in Microsoft Access.

Statistics

Views

Total Views
1,022
Views on SlideShare
1,022
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    AIN102D Access date functions sample queries AIN102D Access date functions sample queries Presentation Transcript

    • AIN102 Access Query Design Samples Module – Date Functions P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.d2associates.com [email_address]
    • AIN102
      • Session 1 – Review of Relational Databases and Single Table Retrieval, Functions and Operators
      • Session 2 – Multi-table retrieval, Sub queries, Unions, Action Queries, Indexes
      • Bonus Modules – Sample Date and String Functions
      Admissions AIN102 Module 1
    • AIN102
      • Lecture/discussion with demonstrations
        • Mostly practical, but a dose of “theory”
      • Assumes some familiarity with MS Access
      • Hands-on
      • Exercises (Mostly cumulative)
      • About 3 hours per module
      • Frequent breaks
      Admissions AIN102 Module 1
    • Microsoft Access Query Design
      • Focus of this class will be on the Query Designer, with SQL used from time-to-time to explain concepts
      • Queries are widely used for:
        • Database administration
        • Enterprise application development
        • Data driven web sites
        • Retrieving and modifying data in MS Access databases
      • A foundation skill for eBusiness and almost all major business applications that use relational databases
      Admissions AIN102 Module 1
    • Access Query Design and SQL
      • The SQL engine Access uses is called JET
      • It support both MS Access and Visual Basic
      • Looking “behind the scenes” at your queries in SQL can be helpful and we will do this; however SQL is not necessary except for UNION queries
      Admissions AIN102 Module 1
    • Relational Database Basics
      • Storage
      • Databases
      • Tables
      • Rows
      • Columns
      • Indexes
      • Views
      • SQL interface
      Admissions AIN102 Module 1
    • Storage
      • In Access one file with extension mdb. I.e mydatabase.mdb .
      • Database splitter can be used to split it into two parts – a front end and a back end.
      • Interface to physical storage via the “JET” database engine. This is the behind-the scenes-workhorse.
      Admissions AIN102 Module 1
    • Databases
      • In the Access world refers to all objects stored in the mdb.
        • Tables
        • Queries
        • From
        • Reports
        • Macros
        • Code modules
      Admissions AIN102 Module 1
    • Admissions AIN102 Module 1 Relational Database Table
    • Admissions AIN102 Module 1 Sample Access Database
    • Admissions AIN102 Module 1 Database Relationships
    • Approaching Query Design
      • Try to build queries a step at a time
      • Save existing queries that are working as you like; modify them with a new name when building a modified query
      • Try looking at the generated SQL code from time-to-time
      Admissions AIN102 Module 1
    • Sample Database
      • Before we continue…
      • Load the sample database if you haven’t already
      Admissions AIN102 Module 1
    • Query Designer Admissions AIN102 Module 1 Right click anywhere for SQL View Double click or drag to add a field Double click to add a table
    • Date Functions
      • The Date functions include
      • - Date()
      • - DateAdd()
      • - DateDiff()
      • - DatePart()
      • - etc.
      Admissions AIN102 Module 1
    • Date Functions (Cont’d)
      • The Date functions include
        • Month()
        • Year()
        • Etc.
      Admissions AIN102 Module 1
    • Date()
      • This function returns the current system date.
      • Create a sample query and save as qrySample_Date.
      • Now add Admissions table.
      • Type Current Date: Date() in field. Save.
      Admissions AIN102 Module 1
    • Add Table Admissions AIN102 Module 1 Doubl click Admissions to add
    • Result Admissions AIN102 Module 1 Current System Date
    • DateAdd()
      • Syntax : DateAdd(interval, number, date)
      • - interval: string expression that is the interval of time you want to add.
      • - number: numeric expression that is the number of interval you want add.
      • - date: date to which the interval is added.
      Admissions AIN102 Module 1 yyyy - Year q - Quarter m- Month y - Year d - Day w -Weekday ww - Week h - Hours n - Minutes s - second
    • DateAdd()
      • Create a query and save as qrySample_DateAdd1.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: After 5 Years: DateAdd ("yyyy", 5,Admissions.Admit_Date). Save.
      • This will add 5 years to the Admit Date.
      Admissions AIN102 Module 1
    • DateAdd() Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1 Admit Date After 5 Years
    • DateAdd()
      • Create a query and save as qrySample_DateAdd2.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: DateAdd(“m”,3,Admissions.Admit_Date) as [After 3 Months]. Save.
      • This will add 3 months to the Admit Date.
      Admissions AIN102 Module 1
    • DateAdd() Admissions AIN102 Module 1
    • DateAdd() Admissions AIN102 Module 1 Admit Date After 3 Months
    • DateDiff()
      • Syntax: DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])
      • - interval: string expression that is the interval of time you use to calculate the difference between date1 and date2.
      • - date1, date2: two dates you want to use in the calculation.
      • - firstdayofweek(optional): A constant that specifies the first day if the week. If not specified, Sunday is assumed.
      • - firstweekofyear(optional): A constant the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs.
      Admissions AIN102 Module 1
    • DateDiff()
      • Create a query and save as qrySample_DateDiff.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date, Dischg_Date.
      • Right click on field and click on Build.
      • Build: DateDiff("d", Admissions.Admit_Date, Admissions.Dischg_Date) as [Date Difference] . Save.
      • This will show the difference between Admit Date and Discharge Date.
      Admissions AIN102 Module 1
    • DateDiff() Admissions AIN102 Module 1
    • DateDiff() Admissions AIN102 Module 1 Difference Between Admit and Discharge Date
    • DatePart()
      • Syntax: DatePart(interval, date[, firstdayofweek[,firstweekofyear]])
      • - interval: string expression that is the interval of time you want to return. .
      • - date: Variant (Date) value that you want to evaluate.
      • - firstdayofweek(optional): A constant that specifies the first day if the week. If not specified, Sunday is assumed.
      • - firstweekofyear(optional): A constant the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs.
      Admissions AIN102 Module 1
    • DatePart()
      • Create a query and save as qrySample_DatePart1.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: DatePart("m", Admissions.Admit_Date) as [Month Of Admission Date] . Save.
      • This will show the month of the Admit Date.
      Admissions AIN102 Module 1
    • DatePart() Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1 Month of Admit Date
    • DatePart()
      • Create a query and save as qrySample_DatePart2.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: DatePart(“yyyy", Admissions.Admit_Date) as [Year Of Admission Date] . Save.
      • This will show the year of the Admit Date.
      Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1 Year of Admit Date
    • DateSerial()
      • Returns a Variant (Date) for a specified year, month, and day.
      • Syntax: DateSerial(year, month, day)
      • - year: Number between 100 and 9999, inclusive, or a numeric expression.
      • - month Integer. Any numeric expression.
      • - day: Integer. Any numeric expression.
      Admissions AIN102 Module 1
    • DateSerial()
      • Create a query and save as qrySample_DateSerial.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: DatePart("yyyy", Admissions.Admit_Date) as [Year Of Admission Date] . Save.
      • Right click on field and click on Build.
      • Build: ], DateSerial( DatePart("yyyy", Admissions.Admit_Date), 12, 31) as [Last Date Of Year] . Save.
      • This will show the last date of respective year of the Admit Date.
      Admissions AIN102 Module 1
    • DateSerial() Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1 Last Date of Admit Year
    • DateValue()
      • Returns a Variant (Date).
      • Syntax: DateValue(date)
      • - date: Generally it is a string expression representing date and it should be separated by valid date separator.
      Admissions AIN102 Module 1
    • DateValue()
      • Create a query and save as qrySample_DateValue1
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: DateValue("February 12, 2003") As [Date Value] . Save.
      • This will show “2/12/2003” in the Date Value column.
      Admissions AIN102 Module 1
    • DateValue() Admissions AIN102 Module 1
    • Result() Admissions AIN102 Module 1 Date Value
    • DateValue()
      • Create a query and save as qrySample_DateValue2
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: DateValue("February 12") As [Date Value] . Save.
      • This will show “2/12/2007” in the Date Value column i.e. it will consider the current system year.
      Admissions AIN102 Module 1
    • Result() Admissions AIN102 Module 1 Date Value
    • Day()
      • Returns a Variant (Integer) specifying a whole number between 1 and 31, inclusive, representing the day of the month.
      • Syntax: Day(date)
      • - date: Generally it is a variant, numeric expression, string expression representing date.
      Admissions AIN102 Module 1
    • Day()
      • Create a query and save as qrySample_Day1.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: Day(Admissions.Admit_Date) AS [Day] . Save.
      • This will show the day of Admit Date.
      Admissions AIN102 Module 1
    • Day() Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1 Day
    • Day()
      • Create a query and save as qrySample_Day2.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: Day: Day(Admissions.Admit_Date) .
      • Type 1 in Criteria. Save.
      • This will show those many records whose day of Admit Date is “1”.
      Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1 (Day = 1)
    • Month()
      • Returns a Variant (Integer) specifying a whole number between 1 and 12, inclusive, representing the day of the month.
      • Syntax: Month(date)
      • - date: Generally it is a variant, numeric expression, string expression representing date.
      Admissions AIN102 Module 1
    • Month()
      • Create a query and save as qrySample_Month1.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: Month(Admissions.Admit_Date) AS [Month] . Save .
      • This will show the month of Admit Date.
      Admissions AIN102 Module 1
    • Month() Admissions AIN102 Module 1
    • Result() Admissions AIN102 Module 1 Month
    • Month()
      • Create a query and save as qrySample_Month1.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: Month(Admissions.Admit_Date) AS [Month] .
      • Type 10 in Criteria. Save.
      • This will show those many records whose month of Admit Date is “10”.
      Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1 Month=10
    • Year()
      • Returns a Variant (Integer) specifying a whole number.
      • Syntax: Year(date)
      • - date: Generally it is a variant, numeric expression, string expression representing date.
      Admissions AIN102 Module 1
    • Year()
      • Create a query and save as qrySample_Year1.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: Year(Admissions.Admit_Date) AS [Year] . Save.
      • This will show the year of Admit Date.
      Admissions AIN102 Module 1
    • Year() Admissions AIN102 Module 1
    • Result() Admissions AIN102 Module 1 Year
    • Year()
      • Create a query and save as qrySample_Year2.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: Year(Admissions.Admit_Date) AS [Year] .
      • Type 2001 in Criteria. Save.
      • This will show those many records whose year of Admit Date is “2001”.
      Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1 Year=2001
    • WeekDay()
      • Returns a Variant(Integer) containing a whole number representing the day of the week.
      • Syntax: WeekDay(date[, firstdayofweek])
      • - date: Variant, numeric expression, string expression, or any combination, that can represent a date.
      • - firstdayofweek (optional): A constant that specifies the first day if the week. If not specified, Sunday is assumed.
      Admissions AIN102 Module 1 firstdayofweek: 0 - API setting 1 - Sunday 2 - Monday 3 - Tuesday 4 - Wednesday 5 - Thursday 6 - Friday 7 - Saturday
    • WeekDay()
      • Create a query and save as qrySample_WeekDay1.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: WeekDay(Admissions.Admit_Date) AS [Week Day] . Save.
      • This will show the week day of Admit Date.
      Admissions AIN102 Module 1
    • WeekDay() Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1 Week Day
    • WeekDay()
      • Create a query and save as qrySample_WeekDay2.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: WeekDay(Admissions.Admit_Date, 2) AS [Week Day] . Save.
      • This will set the first day of the week to Monday(2) and show the week day of Admit Date.
      Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1 Week Day
    • WeekDayName()
      • Returns a string indicating the specified day of the week.
      • Syntax: WeekDayName(weekday[, abbreviate[, firstdayofweek]])
      • - weekday: The numeric designation for the day of the week. Numeric value of each day depends on setting of the firstdayofweek setting.
      • - abbreviate(optional): Boolean value that indicates if the weekday name is to be abbreviated. Default False( Not abbreviated).
      • - firstdayofweek(optional): A constant that specifies the first day if the week. If not specified, Sunday is assumed.
      Admissions AIN102 Module 1
    • WeekDayName()
      • Create a query and save as qrySample_WeekDayName1.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: WeekDayName (WeekDay(Admissions. Admit_Date)) AS [Week Day Name] . Save.
      • This will show the week day name of Admit Date.
      Admissions AIN102 Module 1
    • WeekDayName() Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1 Week Day Name
    • WeekDayName()
      • Create a query and save as qrySample_WeekDayName2.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: WeekDayName (WeekDay(Admissions. Admit_Date),True) AS [Week Day Name] . Save.
      • This will show the abbreviated week day name of Admit Date.
      Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1 Abbreviated Week Day Name
    • MonthName()
      • Returns a string indicating the specified month.
      • Syntax: MonthName( month [, abbreviate ])
      • - month: The numeric designation of the month. For example, January is 1, February is 2, and so on.
      • - abbreviate(optional): Boolean value that indicates if the weekday name is to be abbreviated. Default False( Not abbreviated).
      Admissions AIN102 Module 1
    • MonthName()
      • Create a query and save as qrySample_MonthName.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: Monthname (Month(Admissions. Admit_Date)) as [Month Name] . Save.
      • This will show the month name of Admit Date.
      Admissions AIN102 Module 1
    • MonthName() Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1 MonthName
    • Now()
      • Returns a Variant (Date) specifying the current date and time according your computer's system date and time.
      • Syntax: Now
      • Create a sample query and save as qrySample_Now.
      • Now add Admissions table.
      • Build [Now]: Now() in field. Save.
      • This will show the current system date and time.
      Admissions AIN102 Module 1
    • Now() Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1 Current System Date and Time
    • Hour()
      • Returns a Variant (Integer) specifying a whole number between 0 and 23, inclusive, representing the hour of the day.
      • Syntax: Hour(time)
      • - time: Time is any Variant, numeric expression, string expression, or any combination, that can represent a time.
      Admissions AIN102 Module 1
    • Minute()
      • Returns a Variant (Integer) specifying a whole number between 0 and 59, inclusive, representing the minute of the hour.
      • Syntax: Minute(time)
      • - time: Time is any Variant, numeric expression, string expression, or any combination, that can represent a time.
      Admissions AIN102 Module 1
    • Second()
      • Returns a Variant ( Integer ) specifying a whole number between 0 and 59, inclusive, representing the second of the minute.
      • Syntax: Second(time)
      • - time: Time is any Variant, numeric expression, string expression, or any combination, that can represent a time.
      Admissions AIN102 Module 1
    • Hour(), Minute() and Second()
      • Create a query and save as qrySample_Hour_Minute_Second.
      • Now add Admissions table.
      • Select AdmitNo and Admit_Date.
      • Right click on field and click on Build.
      • Build: Now as [Now], Hour(now) as [Hour], Minute(Now) as [Minute], Second(Now) As [Second] . Save.
      • This will show the hour, minute and second of current system date and time.
      Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1
    • Time()
      • Returns a Variant (Date) indicating the current system time.
      • Syntax: Time
      • Create a sample query and save as qrySample_Time.
      • Now add Admissions table.
      • Build: [Now] as [Now], Time() as [Time] in field. Save.
      • This will show the current system time.
      Admissions AIN102 Module 1
    • Time() Admissions AIN102 Module 1
    • TimeSerial()
      • Returns a Variant (Date) containing the time for a specific hour, minute, and second.
      • Syntax: TimeSerial( hour, minute, second )
      • - hour: Variant (Integer). Number between 0 (12:00 A.M.) and 23 (11:00 P.M.), inclusive, or a numeric expression.
      • - minute: Variant (Integer). Any numeric expression.
      • - second Required; Variant (Integer). Any numeric expression.
      Admissions AIN102 Module 1
    • TimeSerial()
      • Create a sample query and save as qrySample_TimeSerial.
      • Now add Admissions table.
      • Build: TimeSerial (5,15,12) as [Time Serial] in field. Save.
      • This will show 5:15:12 AM.
      Admissions AIN102 Module 1
    • Result Admissions AIN102 Module 1 [end module]