Notices


Reply
 
LinkBack Thread Tools Display Modes

Old 07-28-2008, 08:53 AM   #1 (permalink)
ET - outta this world!

Elaine Tucker's Avatar

Join Date: May 2006
Location: Dallas, Texas
Posts: 689
Rep Power: 3 Elaine Tucker is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- Financial Edge (FE)
- Education Edge (EE)

MS Access and query date = This week

Hey ya'll.

I've got an access db that has a field of "Date of Occurrance"

I need to query on date = This week based on comparing "today" (Now) with the Date of Occurrance.

I have calculated the weekday value using Weekday([Date of Occurrance}) and that works to get me the 1,2,3,4,5,6,or 7 value.

What now?
__________________
Elaine Tucker
Stewardship Coordinator
St. Mark's School of Texas
USA
www.smtexas.org
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 07-28-2008, 09:03 AM   #2 (permalink)
Crystal Reports Guru

DrewAllen's Avatar

Join Date: May 2006
Location: Philadelphia, PA
Posts: 1,160
Rep Power: 4 DrewAllen is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- Information Edge (TIE)
- API/VBA

Use the DateDiff() function. MS Access, Crystal Reports, and MS SQL Server all have this function, but they all use slightly different syntax. Use the MS Access Help to find the correct syntax.

Code:
DateDiff("w", {Date of Occurence}, Today) = 0
Drew
__________________
J. Drew Allen
Children's Hospital of Philadelphia

Crystal Reports and SQL Server Consultant

It is better to live your destiny imperfectly than to live an imitation of somebody else's life with perfection.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 07-28-2008, 10:26 AM   #3 (permalink)
RDC:RE Guy

mwittman's Avatar

Join Date: Sep 2007
Posts: 155
Rep Power: 2 mwittman is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- NetCommunity (BBNC)

Drew's solution is right on for "week" as in any "7 days" or "5 days" backward or forward from Date of Occurrence.

For (MS Access) "Are these two dates in the same calendar week":


IIf( (DatePart("ww", [Date of Occurence])) = (DatePart("ww", Now()), "Same Week", "Different Week" )
__________________
Micah Wittman

WORK

Database Coordinator
Red Deer College
blackbus4.m.wittman@xoxy.net

PERSONAL

http://bebepool.com
http://hmatters.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 07-28-2008, 11:16 AM   #4 (permalink)
Crystal Reports Guru

DrewAllen's Avatar

Join Date: May 2006
Location: Philadelphia, PA
Posts: 1,160
Rep Power: 4 DrewAllen is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- Information Edge (TIE)
- API/VBA

Quote:
Originally Posted by mwittman View Post
Drew's solution is right on for "week" as in any "7 days" or "5 days" backward or forward from Date of Occurrence.

For (MS Access) "Are these two dates in the same calendar week":


IIf( (DatePart("ww", [Date of Occurence])) = (DatePart("ww", Now()), "Same Week", "Different Week" )
This is why I recommended reading the documentation. MS Access has two different "week" date parts. "w" uses the weekday of the first date as the beginning of the week, whereass "ww" uses the system default (usually Sunday in the US) as the start of the week unless the optional parameter to set the start of the week is provided.

Crystal Reports has the same distinction as MS Access. On the other hand, MS SQL Server only ever uses the system default.

WARNING: mwittman's formula above fails when the Date of Occurrence and Today fall in the same calendar week, but in different calendar years. If you simply replace the "w" with a "ww" in my original formula, it will work.

Drew
__________________
J. Drew Allen
Children's Hospital of Philadelphia

Crystal Reports and SQL Server Consultant

It is better to live your destiny imperfectly than to live an imitation of somebody else's life with perfection.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 07-28-2008, 11:51 AM   #5 (permalink)
RDC:RE Guy

mwittman's Avatar

Join Date: Sep 2007
Posts: 155
Rep Power: 2 mwittman is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- NetCommunity (BBNC)

Quote:
Originally Posted by DrewAllen View Post
This is why I recommended reading the documentation. MS Access has two different "week" date parts. "w" uses the weekday of the first date as the beginning of the week, whereass "ww" uses the system default (usually Sunday in the US) as the start of the week unless the optional parameter to set the start of the week is provided.

Crystal Reports has the same distinction as MS Access. On the other hand, MS SQL Server only ever uses the system default.

WARNING: mwittman's formula above fails when the Date of Occurrence and Today fall in the same calendar week, but in different calendar years. If you simply replace the "w" with a "ww" in my original formula, it will work.

Drew
Drew is correct - in your case, Elaine, the year must be checked as well (other use cases may intentional ignore the year b/c "same week # of given year" is what needs to be tested).

So, if you want to customize the firstDayOfWeek parameter, or othewise like writing and maintaining more code, use something like this (MS Access only):

IIf((Year([Date of Occurence]) & DatePart("ww",[Date of Occurence])) = (Year(Now()) & DatePart("ww",Now())),"Same Week","Different Week")

...
__________________
Micah Wittman

WORK

Database Coordinator
Red Deer College
blackbus4.m.wittman@xoxy.net

PERSONAL

http://bebepool.com
http://hmatters.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 07-28-2008, 12:26 PM   #6 (permalink)
ET - outta this world!

Elaine Tucker's Avatar

Join Date: May 2006
Location: Dallas, Texas
Posts: 689
Rep Power: 3 Elaine Tucker is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- Financial Edge (FE)
- Education Edge (EE)

Thanks so much Micah & Drew! I kept trying the DatePart and DateDiff yesterday, but kept getting an error message (of course I can't replicate it now... lol)... also I was thrown by the access "help" because the format I was prompted for was:

DateDiff («interval», «date1», «date2», «firstweekday», «firstweek») and for the life of me I couldn't figure out the firstwekday and the firstweek parameters.... yea that was a DUH on my part.

However the formula that ya'll came up with will work so much better. I haven't actually tried it yet, but it makes logical sense to me (at least at the moment).

Rock!
__________________
Elaine Tucker
Stewardship Coordinator
St. Mark's School of Texas
USA
www.smtexas.org
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 07-28-2008, 12:41 PM   #7 (permalink)
ET - outta this world!

Elaine Tucker's Avatar

Join Date: May 2006
Location: Dallas, Texas
Posts: 689
Rep Power: 3 Elaine Tucker is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- Financial Edge (FE)
- Education Edge (EE)

IT Works! YAHOOOO********>!!!!!

Muchas Gracias!!!
__________________
Elaine Tucker
Stewardship Coordinator
St. Mark's School of Texas
USA
www.smtexas.org
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 07-28-2008, 12:54 PM   #8 (permalink)
Crystal Reports Guru

DrewAllen's Avatar

Join Date: May 2006
Location: Philadelphia, PA
Posts: 1,160
Rep Power: 4 DrewAllen is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- Information Edge (TIE)
- API/VBA

Quote:
Originally Posted by mwittman View Post
Drew is correct - in your case, Elaine, the year must be checked as well (other use cases may intentional ignore the year b/c "same week # of given year" is what needs to be tested).
No, that's the point I'm trying to make. If you use the correct tool, you don't need to check the year. It's handled automatically. DateDiff() is the correct tool, DatePart() is not.

The formula should be
Code:
DateDiff("ww", [Date of Occurence],Now())
Drew
__________________
J. Drew Allen
Children's Hospital of Philadelphia

Crystal Reports and SQL Server Consultant

It is better to live your destiny imperfectly than to live an imitation of somebody else's life with perfection.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 07-28-2008, 12:59 PM   #9 (permalink)
ET - outta this world!

Elaine Tucker's Avatar

Join Date: May 2006
Location: Dallas, Texas
Posts: 689
Rep Power: 3 Elaine Tucker is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- Financial Edge (FE)
- Education Edge (EE)

Got it... I'll use the dynamic one -- with DateDiff
__________________
Elaine Tucker
Stewardship Coordinator
St. Mark's School of Texas
USA
www.smtexas.org
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 08-18-2008, 05:38 PM   #10 (permalink)
RDC:RE Guy

mwittman's Avatar

Join Date: Sep 2007
Posts: 155
Rep Power: 2 mwittman is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- NetCommunity (BBNC)

Quote:
Originally Posted by DrewAllen View Post
No, that's the point I'm trying to make. If you use the correct tool, you don't need to check the year. It's handled automatically. DateDiff() is the correct tool, DatePart() is not.

The formula should be
Code:
DateDiff("ww", [Date of Occurence],Now())
Drew
To quote Grey's Anatomy (the TV show) "This is a teaching hospital, Dr _______".

Ideas and examples written to this forum can bring insight to a whole class of problems and not just the one presented in the original question. Discussing more than one solution can facilitate the serendipity of applying information gleaned from challenge A to solving challenge B.

I'm all for persuading the community with the merits of a claim - sure! but what I don't agree with is the notion of "the correct tool". "Less verbose construct", "more readable code", "a tool with fewer dependencies on the system configuration", "applying Occam's razor..." — sprinkle those over an argument and now we've got a satisfying debate.

When I stated:
" the year must be checked as well (other use cases may intentional ignore the year b/c "same week # of given year" is what needs to be tested)"
"the year must be checked", whether internally with DateDiff() or externally with DatePart() - either can be used to give the correct result. The DatePart() method is more verbose code, and that's why I had wirtten the ironic, self-deprecating: use my solution "if you...like writing and maintaining more code".

Note-to-self: Work on my ironic delivery.

Anyway, my goal is not to start a flame war, but to explain myself. And I'll say it again: Drew is right; Elaine's specific problem is cleanly solved with DateDiff(), and you've confirmed that, Elaine. It's all good.
__________________
Micah Wittman

WORK

Database Coordinator
Red Deer College
blackbus4.m.wittman@xoxy.net

PERSONAL

http://bebepool.com
http://hmatters.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 08-19-2008, 10:01 AM   #11 (permalink)
ET - outta this world!

Elaine Tucker's Avatar

Join Date: May 2006
Location: Dallas, Texas
Posts: 689
Rep Power: 3 Elaine Tucker is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- Financial Edge (FE)
- Education Edge (EE)

I appreciate all the help on the forum - especially the explanation of the differences in the formulas that the "everyday" person can understand.

I struggled for quite a while trying to figure out on my own the difference between all the date formulas in crystal... (apparently I need to get one of the Nut books that is more up-to-date than my reference book...)

Since ya'll have practical experience in the real world it really helps to keep reminded of all the little details that can cause reports and formulas to go awry.
__________________
Elaine Tucker
Stewardship Coordinator
St. Mark's School of Texas
USA
www.smtexas.org
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
date, query, this week


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Debt Consolidation - Credit Counseling - Credit Card - Mortgage
All times are GMT -6. The time now is 01:56 AM.

Miscellaneous


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by BBpixel Team 2008 :: jvbPlugin R1012.364.1

SEO by vBSEO 3.2.0 Copyright 2008 Blackbaud User SocietyAd Management by RedTyger
Inactive Reminders By Icora Web Design

1 2 3 4 5 6 7 8 9 10 11 12 13 14