SlideShare a Scribd company logo
1 of 7
Query criteria 2: Using date criteria in queries
j
then press F5 or click Slide Show > From Beginning to start the course.
In the message bar, click Enable Editing,
If the videos in this course don’t play, you may need to
download QuickTime or just switch to PowerPoint 2013.
5 61 2 3 4
Course summary Help
1/3 videos
Query criteria 2: Using date criteria in queries Closed captions
Summary Feedback HelpThe basics Calculated fields DateDiff, DateAdd
4:182:30 3:17
Press F5 to start, Esc to stop
When you use criteria to filter your query results, date criteria can be kind of tricky.So in this course, I'll show you how to use date criteria in queries, starting with the basics.To filter for date values, you surround them with pound signs, like this.If you don't use pound signs, you won't get a result.And remember, you need to enter the entire value in the field. If you enter part of one, like this, you won't
get a result.
Now, the example you just saw filtered for a single date.If you want more flexibility, you can use the Or operator, like this.You can also use some basic expressions.An expression is a combination of functions, logical operators, constants, and fields.For example, I can use the NOT operator to find everything but assets purchased on April 4th of 2013.I can also use the greater-than sign to find dates after April 4th, like so,or the less-than sign to find all dates before April 4th.Just remember to put your operators outside the pound signs.You can also use the AND operator.For example, this criteria finds all records after the second and before the fourteenth.If you need to include data from the dates listed, use BETWEEN and AND.And I know I've said it before, but remember to surround your date values with pound signs.And while I'm repeating myself, remember that pound signs return entire date values.You can't use them to find part of a date, like this.If you need to filter for part of a date, just years or months, for example, you can create a calculated field,and we'll look at how to do that in the next video.
5 61 2 3 4
Course summary Help
2/3 videos
Query criteria 2: Using date criteria in queries Closed captions
Summary Feedback Help
Press F5 to start, Esc to stop
The basics Calculated fields DateDiff, DateAdd
4:182:30 3:17
The expressions we saw in the previous video only work on whole date values.For example, this expression returns data for all dates except March 22nd of 2013.But if I only use part of the date value in my expressions, I get no result.So, when you need to filter on part of a date value, you can use a calculated field.Calculated fields don't exist in your data.Instead, they display the results of calculation that you define in a new field in your query.As a first example, I'll filter for assets purchased in a given year.Click the top row of a blank field, enter equals, YEAR—that's the function—and a set of parentheses.In the parentheses, add a pair of brackets, and then Acquired Date, the field with my date values.In the Criteria row, I'll enter 2013, and notice that I don't use quotes or pound signs around the value.You do that because the YEAR function returns a number, so I can just use the number here.I'll also hide the Acquired Date field, that makes the data easier to read,and you can see the criteria filters for assets purchased in 2013.So back to Design view, and notice this: Access gave the field a name and removed the equal sign.That's normal, and if you want to, you can rename the field, another way to make your data easier to
understand.
Also, you need to remember a key piece of syntax.When you use a field name in an expression, and the name has spaces, put it in brackets, like this.Capitalization doesn't matter, but spelling does.As another example, say your boss needs to know what was purchased during the second quarter of 2013.For this I'll use the DatePart function, because it lets me filter on time intervals—months, and so on.The function uses any of ten interval settings, from years down to seconds, and here they are.And don't try to memorize these now. The course summary has links to this information.The function also requires a date, either a specific date, or a list of dates in a field.So after DatePart, I enter “q” because I want to filter by quarter, and make sure you use quotes around this
setting.
Add a comma after the quotes, and then Acquired Datebecause that's the field where the date values are, and don't forget the brackets.Now enter 2 in the Criteria row, because you want results for the second quarter, and run the query.Finally, you can do a lot more with expressions than what you've seen here,so the course summary has links to more information.Next, we'll see how to calculate intervals between dates with the DateDiff function,and how to add or subtract dates with the DateAdd function.
5 61 2 3 4
Course summary Help
3/3 videos
Query criteria 2: Using date criteria in queries Closed captions
Summary Feedback Help
Press F5 to start, Esc to stop
The basics Calculated fields DateDiff, DateAdd
4:182:30 3:17
Let's look at how to use the DateDiff and DateAdd functions in query criteria, and we'll start with DateDiff.DateDiff calculates the number of time intervals, such as days or months, between two Date/Time values.The function requires an interval setting, followed by a start date and an ending date.Here's a list of the interval settings, and don't try to memorize them now. The course summary has a link to
them.
So as an example, here's a query that returns order data—when an order was placed, when it was due, and
when it was shipped.
Now let's say you need to know which orders were late, and by how many days.Go to Design View, expand a blank field, enter a field name, a colon, DateDiff, and parentheses.I want to know how many days an order was late, so I enter “d”, the day interval, with the quotes, and a
comma after.
For my starting and ending dates, I'll enter brackets, with a comma between them, then the field names.That way, I don't forget the brackets.Now let's stop and go back to the unfiltered data for a moment.You can see that not all of the orders are late. Some are early, and some are on time.So if I run my query as it is now, I get a lot of negative values, and those numbers point to orders that
shipped on time.
Because I only want to see late orders, I enter a greater-than sign and zero in the Criteria row,and sort the results in Descending order.Run the query, and there you go.You use the DateAdd function when you need to add date values together.DateAdd works a lot like DateDiff, but it uses slightly different syntax.You start with an interval, but then you specify a number, and this is the number of intervals you want to
add.
So if I specify the year interval, then 3, I'm adding 3 years' worth of values.You follow that with a date, and this is the date you'll add your values to.So in this example, I'm filtering for three years' worth of data, starting with October 16th of 2015.To show you how this works, I'll use the Criteria row instead of a calculated field,and I'll filter for records from the past four years.Start with the Between operator, then the Date function.That gives me a date automatically, so I don't have to enter one each time I run this query.It saves me some typing.Follow that with the AND operator, then DateAdd, parentheses,the year interval, negative four, and then the Date function again.The second date function is there because DateAdd has to add your values to something,and the Date function provides that something—today's date.You can also use specific dates, like this, but make sure you surround them with quotes.Run the query, and I get earlier dates, records from the past four years.Change the interval number to a positive number, and I get later values.Now, that's just one example of how to use the DateAdd function, so see the Course Summary for links to
more information.
Help Course summary
Press F5 to start, Esc to stop
Course summary—Query criteria 2: Using date criteria in queries
Summary Feedback Help
5 61 2 3 4
The basics Calculated fields DateDiff, DateAdd
4:182:30 3:17
See also
• Using dates as criteria in Access queries
• Build an expression
• Choose the right date function
• DatePart, DateDiff, & DateAdd
• More training courses
• Office Compatibility Pack
The basics
Surround your date values with pound signs (#). For
example, #4/1/1997#. Also, keep logical operators
outside pound signs.
• #4/1/1997# Or #5/4/1997#
• >=#5/4/1997# Or <=#6/12/1998#
Filter for a given year
=Year([Acquired Date]), then put the year you want to
filter for in the Criteria row.
Filter for an interval (year,
quarter, etc.)
=DatePart("q",[acquired date]). In this example, put the
numbers 1-4 (the quarter you want to filter for) in the
Criteria row.
Subtract dates
=DateDiff("d",[RequiredDate],[ShippedDate]). Finds the
days between a required date and a shipped date.
Add dates
=DateAdd("m",6,"4/1/1997") Finds 6 months of data,
starting with the date provided.
DatePart, DateDiff, & DateAdd
interval settings
yyyy
q
m
y
d
w
ww
h
n
s
Year
Quarter
Month
Day of year
Day
Weekday
Week
Hour
Minute
Seconds
Check out more courses
Help Course summary
Press F5 to start, Esc to stop
Rating and comments
Thank you for viewing this course!
Please tell us what you think
Summary Feedback Help
5 61 2 3 4
The basics Calculated fields DateDiff, DateAdd
4:182:30 3:17
Help Course summary
Press F5 to start, Esc to stop
Help
Summary Feedback Help
5 61 2 3 4
Using PowerPoint’s video controls
Going places
Stopping a course
If you download a course and the videos don’t play
get the PowerPoint Viewer. the QuickTime
player upgrade to PowerPoint 2013
The basics Calculated fields DateDiff, DateAdd
4:182:30 3:17

More Related Content

More from Mustansir Dahodwala (20)

English Portfolio
English Portfolio English Portfolio
English Portfolio
 
Monopoly rules
Monopoly rulesMonopoly rules
Monopoly rules
 
Hello there
Hello thereHello there
Hello there
 
Happy birthday Card
Happy birthday CardHappy birthday Card
Happy birthday Card
 
Happy Birthday School Card
Happy Birthday School CardHappy Birthday School Card
Happy Birthday School Card
 
GTA San cheats
GTA San cheatsGTA San cheats
GTA San cheats
 
Core Values
Core ValuesCore Values
Core Values
 
Flower
Flower Flower
Flower
 
Fake Children Money
Fake Children MoneyFake Children Money
Fake Children Money
 
Book Review
Book ReviewBook Review
Book Review
 
Gift Card
Gift CardGift Card
Gift Card
 
Birthday Card
Birthday CardBirthday Card
Birthday Card
 
Social Studies Portfolio
Social Studies PortfolioSocial Studies Portfolio
Social Studies Portfolio
 
Science Portfolio
Science PortfolioScience Portfolio
Science Portfolio
 
Mathematics Portfolio
Mathematics PortfolioMathematics Portfolio
Mathematics Portfolio
 
Islamic Portfolio
Islamic PortfolioIslamic Portfolio
Islamic Portfolio
 
History Portfolio
History PortfolioHistory Portfolio
History Portfolio
 
Hindi Portfolio
Hindi PortfolioHindi Portfolio
Hindi Portfolio
 
English Portfolio
English PortfolioEnglish Portfolio
English Portfolio
 
A gift for you
A gift for youA gift for you
A gift for you
 

Recently uploaded

Reconciling Conflicting Data Curation Actions: Transparency Through Argument...
Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...
Reconciling Conflicting Data Curation Actions: Transparency Through Argument...Bertram Ludäscher
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabiaahmedjiabur940
 
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样wsppdmt
 
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...nirzagarg
 
Harnessing the Power of GenAI for BI and Reporting.pptx
Harnessing the Power of GenAI for BI and Reporting.pptxHarnessing the Power of GenAI for BI and Reporting.pptx
Harnessing the Power of GenAI for BI and Reporting.pptxParas Gupta
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...gajnagarg
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...gajnagarg
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制vexqp
 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...Health
 
Data Analyst Tasks to do the internship.pdf
Data Analyst Tasks to do the internship.pdfData Analyst Tasks to do the internship.pdf
Data Analyst Tasks to do the internship.pdftheeltifs
 
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制vexqp
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...nirzagarg
 
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制vexqp
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...Elaine Werffeli
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Klinik kandungan
 
The-boAt-Story-Navigating-the-Waves-of-Innovation.pptx
The-boAt-Story-Navigating-the-Waves-of-Innovation.pptxThe-boAt-Story-Navigating-the-Waves-of-Innovation.pptx
The-boAt-Story-Navigating-the-Waves-of-Innovation.pptxVivek487417
 
Ranking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRanking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRajesh Mondal
 

Recently uploaded (20)

Reconciling Conflicting Data Curation Actions: Transparency Through Argument...
Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...
Reconciling Conflicting Data Curation Actions: Transparency Through Argument...
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
 
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
 
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
 
Sequential and reinforcement learning for demand side management by Margaux B...
Sequential and reinforcement learning for demand side management by Margaux B...Sequential and reinforcement learning for demand side management by Margaux B...
Sequential and reinforcement learning for demand side management by Margaux B...
 
Harnessing the Power of GenAI for BI and Reporting.pptx
Harnessing the Power of GenAI for BI and Reporting.pptxHarnessing the Power of GenAI for BI and Reporting.pptx
Harnessing the Power of GenAI for BI and Reporting.pptx
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
 
Data Analyst Tasks to do the internship.pdf
Data Analyst Tasks to do the internship.pdfData Analyst Tasks to do the internship.pdf
Data Analyst Tasks to do the internship.pdf
 
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
 
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
 
The-boAt-Story-Navigating-the-Waves-of-Innovation.pptx
The-boAt-Story-Navigating-the-Waves-of-Innovation.pptxThe-boAt-Story-Navigating-the-Waves-of-Innovation.pptx
The-boAt-Story-Navigating-the-Waves-of-Innovation.pptx
 
Ranking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRanking and Scoring Exercises for Research
Ranking and Scoring Exercises for Research
 

Microsoft Office Access 2013 Tutorial -Learning Criteria-2

  • 1. Query criteria 2: Using date criteria in queries j then press F5 or click Slide Show > From Beginning to start the course. In the message bar, click Enable Editing, If the videos in this course don’t play, you may need to download QuickTime or just switch to PowerPoint 2013.
  • 2. 5 61 2 3 4 Course summary Help 1/3 videos Query criteria 2: Using date criteria in queries Closed captions Summary Feedback HelpThe basics Calculated fields DateDiff, DateAdd 4:182:30 3:17 Press F5 to start, Esc to stop When you use criteria to filter your query results, date criteria can be kind of tricky.So in this course, I'll show you how to use date criteria in queries, starting with the basics.To filter for date values, you surround them with pound signs, like this.If you don't use pound signs, you won't get a result.And remember, you need to enter the entire value in the field. If you enter part of one, like this, you won't get a result. Now, the example you just saw filtered for a single date.If you want more flexibility, you can use the Or operator, like this.You can also use some basic expressions.An expression is a combination of functions, logical operators, constants, and fields.For example, I can use the NOT operator to find everything but assets purchased on April 4th of 2013.I can also use the greater-than sign to find dates after April 4th, like so,or the less-than sign to find all dates before April 4th.Just remember to put your operators outside the pound signs.You can also use the AND operator.For example, this criteria finds all records after the second and before the fourteenth.If you need to include data from the dates listed, use BETWEEN and AND.And I know I've said it before, but remember to surround your date values with pound signs.And while I'm repeating myself, remember that pound signs return entire date values.You can't use them to find part of a date, like this.If you need to filter for part of a date, just years or months, for example, you can create a calculated field,and we'll look at how to do that in the next video.
  • 3. 5 61 2 3 4 Course summary Help 2/3 videos Query criteria 2: Using date criteria in queries Closed captions Summary Feedback Help Press F5 to start, Esc to stop The basics Calculated fields DateDiff, DateAdd 4:182:30 3:17 The expressions we saw in the previous video only work on whole date values.For example, this expression returns data for all dates except March 22nd of 2013.But if I only use part of the date value in my expressions, I get no result.So, when you need to filter on part of a date value, you can use a calculated field.Calculated fields don't exist in your data.Instead, they display the results of calculation that you define in a new field in your query.As a first example, I'll filter for assets purchased in a given year.Click the top row of a blank field, enter equals, YEAR—that's the function—and a set of parentheses.In the parentheses, add a pair of brackets, and then Acquired Date, the field with my date values.In the Criteria row, I'll enter 2013, and notice that I don't use quotes or pound signs around the value.You do that because the YEAR function returns a number, so I can just use the number here.I'll also hide the Acquired Date field, that makes the data easier to read,and you can see the criteria filters for assets purchased in 2013.So back to Design view, and notice this: Access gave the field a name and removed the equal sign.That's normal, and if you want to, you can rename the field, another way to make your data easier to understand. Also, you need to remember a key piece of syntax.When you use a field name in an expression, and the name has spaces, put it in brackets, like this.Capitalization doesn't matter, but spelling does.As another example, say your boss needs to know what was purchased during the second quarter of 2013.For this I'll use the DatePart function, because it lets me filter on time intervals—months, and so on.The function uses any of ten interval settings, from years down to seconds, and here they are.And don't try to memorize these now. The course summary has links to this information.The function also requires a date, either a specific date, or a list of dates in a field.So after DatePart, I enter “q” because I want to filter by quarter, and make sure you use quotes around this setting. Add a comma after the quotes, and then Acquired Datebecause that's the field where the date values are, and don't forget the brackets.Now enter 2 in the Criteria row, because you want results for the second quarter, and run the query.Finally, you can do a lot more with expressions than what you've seen here,so the course summary has links to more information.Next, we'll see how to calculate intervals between dates with the DateDiff function,and how to add or subtract dates with the DateAdd function.
  • 4. 5 61 2 3 4 Course summary Help 3/3 videos Query criteria 2: Using date criteria in queries Closed captions Summary Feedback Help Press F5 to start, Esc to stop The basics Calculated fields DateDiff, DateAdd 4:182:30 3:17 Let's look at how to use the DateDiff and DateAdd functions in query criteria, and we'll start with DateDiff.DateDiff calculates the number of time intervals, such as days or months, between two Date/Time values.The function requires an interval setting, followed by a start date and an ending date.Here's a list of the interval settings, and don't try to memorize them now. The course summary has a link to them. So as an example, here's a query that returns order data—when an order was placed, when it was due, and when it was shipped. Now let's say you need to know which orders were late, and by how many days.Go to Design View, expand a blank field, enter a field name, a colon, DateDiff, and parentheses.I want to know how many days an order was late, so I enter “d”, the day interval, with the quotes, and a comma after. For my starting and ending dates, I'll enter brackets, with a comma between them, then the field names.That way, I don't forget the brackets.Now let's stop and go back to the unfiltered data for a moment.You can see that not all of the orders are late. Some are early, and some are on time.So if I run my query as it is now, I get a lot of negative values, and those numbers point to orders that shipped on time. Because I only want to see late orders, I enter a greater-than sign and zero in the Criteria row,and sort the results in Descending order.Run the query, and there you go.You use the DateAdd function when you need to add date values together.DateAdd works a lot like DateDiff, but it uses slightly different syntax.You start with an interval, but then you specify a number, and this is the number of intervals you want to add. So if I specify the year interval, then 3, I'm adding 3 years' worth of values.You follow that with a date, and this is the date you'll add your values to.So in this example, I'm filtering for three years' worth of data, starting with October 16th of 2015.To show you how this works, I'll use the Criteria row instead of a calculated field,and I'll filter for records from the past four years.Start with the Between operator, then the Date function.That gives me a date automatically, so I don't have to enter one each time I run this query.It saves me some typing.Follow that with the AND operator, then DateAdd, parentheses,the year interval, negative four, and then the Date function again.The second date function is there because DateAdd has to add your values to something,and the Date function provides that something—today's date.You can also use specific dates, like this, but make sure you surround them with quotes.Run the query, and I get earlier dates, records from the past four years.Change the interval number to a positive number, and I get later values.Now, that's just one example of how to use the DateAdd function, so see the Course Summary for links to more information.
  • 5. Help Course summary Press F5 to start, Esc to stop Course summary—Query criteria 2: Using date criteria in queries Summary Feedback Help 5 61 2 3 4 The basics Calculated fields DateDiff, DateAdd 4:182:30 3:17 See also • Using dates as criteria in Access queries • Build an expression • Choose the right date function • DatePart, DateDiff, & DateAdd • More training courses • Office Compatibility Pack The basics Surround your date values with pound signs (#). For example, #4/1/1997#. Also, keep logical operators outside pound signs. • #4/1/1997# Or #5/4/1997# • >=#5/4/1997# Or <=#6/12/1998# Filter for a given year =Year([Acquired Date]), then put the year you want to filter for in the Criteria row. Filter for an interval (year, quarter, etc.) =DatePart("q",[acquired date]). In this example, put the numbers 1-4 (the quarter you want to filter for) in the Criteria row. Subtract dates =DateDiff("d",[RequiredDate],[ShippedDate]). Finds the days between a required date and a shipped date. Add dates =DateAdd("m",6,"4/1/1997") Finds 6 months of data, starting with the date provided. DatePart, DateDiff, & DateAdd interval settings yyyy q m y d w ww h n s Year Quarter Month Day of year Day Weekday Week Hour Minute Seconds
  • 6. Check out more courses Help Course summary Press F5 to start, Esc to stop Rating and comments Thank you for viewing this course! Please tell us what you think Summary Feedback Help 5 61 2 3 4 The basics Calculated fields DateDiff, DateAdd 4:182:30 3:17
  • 7. Help Course summary Press F5 to start, Esc to stop Help Summary Feedback Help 5 61 2 3 4 Using PowerPoint’s video controls Going places Stopping a course If you download a course and the videos don’t play get the PowerPoint Viewer. the QuickTime player upgrade to PowerPoint 2013 The basics Calculated fields DateDiff, DateAdd 4:182:30 3:17