Solved

firstweekofyear in access 2010

Posted on 2012-03-22
8
289 Views
Last Modified: 2012-03-22
How do you use the constant firstweekofyear in access 2010 DateDiff function?
I am trying to filter if a date result is in previous year, current year or null
0
Comment
Question by:simernet
  • 4
  • 3
8 Comments
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 37753864
That for week calculations, it won't tell you about the year.

Use Year for that:

intYearOfDate = Year(datYourDate)
If intYearOfDate = Year(Date()) Then ' this year.
If intYearOfDate = Year(Date()) - 1 Then ' last year.
Else ' other year.

/gustav
0
 
LVL 33

Expert Comment

by:Norie
ID: 37753904
Not sure what constant you mean.

Anyway you don't need a constant for this, you could use Date /Year in an expression like this.

Switch(IsNull([DateField]), "Null", Year([DateField]) = Year(Date()), "This Year", Year([DateField]) = Year(Date())-1, "last Year")
0
 
LVL 1

Author Comment

by:simernet
ID: 37754051
In english I am looking to see if a date occured anytime in the current year or if it falls anytime withing the previous year.  I also want to know if it is null.  
I have the Null part IsNull([disenrollDate])
0
 
LVL 33

Expert Comment

by:Norie
ID: 37754063
The expression I posted does that and returns a string indicating if its null, in the current year or form last year.

What do you want have returned?
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 1

Author Comment

by:simernet
ID: 37754166
I want this as a filter, so True or False.
I am looking for
True,  IsNull,
True,  This year
True, Last calendar year  ex. (01 JAN 2011  -  31 DEC 2011)
False if any year prior.

Cannot hard code in dates as it will float from year to year.
0
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 37754248
What I posted didn't hardcode anything.

Anyway, just use this in the criteria for the filter.


Not IsNull([disenrollDate]) AND (Year([isenrollDate]) = Year(Date()) OR [disenrollDate]= Year(Date())-1

The Year functions returns the year of a date and Date returns the current date.

So today Year(Date()) returns 2012  but on this day next year will return 2013 and so on.
0
 
LVL 1

Author Comment

by:simernet
ID: 37754347
Year([DisenrollDate])=Year(Date())-1 Or Year([DisenrollDate])=Year(Date()) Or IsNull([DisenrollDate])=True

Thanks,
0
 
LVL 33

Expert Comment

by:Norie
ID: 37754435
Oops, don't know where that AND came from.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now