473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

counting dates

Hi All
I have a table with the fields Month and Year.
I need a query to count the number of occurences before and after the current month. I then intend to place the counts into a form as visits. The count before the current month would be in red and after in green.
Any assistance would be much appreciated.
ChrisD
Dec 19 '06 #1
2 1409
MMcCarthy
14,534 Expert Mod 8TB
Hi All
I have a table with the fields Month and Year.
I need a query to count the number of occurences before and after the current month. I then intend to place the counts into a form as visits. The count before the current month would be in red and after in green.
Any assistance would be much appreciated.
ChrisD
You could try something like this ...

Expand|Select|Wrap|Line Numbers
  1. SELECT Sum(IIf(Month([DateField])<>Month(Now()) And Year([DateField])<>Year(Now()),IIf([DateField]<Now(),1,0),0)) As  NoBefore, Sum(IIf(Month([DateField])<>Month(Now()) And Year([DateField])<>Year(Now()),IIf([DateField]>Now(),1,0),0)) As  NoAfter
  2. FROM TableName;
  3.  
Mary
Dec 21 '06 #2
NeoPa
32,556 Expert Mod 16PB
If your Month & Year fields are 2 and 4 character text fields then :
Expand|Select|Wrap|Line Numbers
  1. SELECT Sum(IIf([Year] & [Month]<Format(Date(),'yyyymm'),1,0)) AS NumRed,
  2.        Sum(IIf([Year] & [Month]>Format(Date(),'yyyymm'),1,0)) AS NumGreen
  3. FROM YourTable
Bear in mind, your request completely excludes all the records for the current month.
Dec 21 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Mr. x | last post by:
Hello, I need a script for counting the no. of enters on my site, please. I need a check that for the same user in the same day - if the user enter several times, it is count once (or something...
14
by: Mike N. | last post by:
Hello: I have a form that contains a multiple-select field that has 12 options in it. I would like the user to be able to select UP TO FOUR of those options. If they select more than four, I...
7
by: Bambero | last post by:
Hello all Problem like in subject. There is no problem when I want to count days between two dates. Problem is when I want to count years becouse of leap years. For ex. between 2002-11-19...
6
by: edwardfredriks | last post by:
I'm looking for a script that, instead of counting down, can "count up" from a given date. So the output should be something like "(xx) days since (date/event)" or "(date/event) was (xx) days ago"....
2
by: David Mitchell | last post by:
I have tried using the following code to count the specific number of each weekday but get a compile error "User defined type not defined" which I think relates to the first line of the function: -...
2
by: BlackFireNova | last post by:
I have an Access 2003 mdb which contains software records. I need to sort on a particular type of software, and then identify and count how many copies there are per each group of that type...
4
by: Alicia | last post by:
I am having a problem grouping by week. I am looking for the simpliest way of doing it in Microsoft Access. I have tried to use a pre-loaded calender, access did not like it at all. If there is...
34
by: Mo Geffer | last post by:
Greetings: I have a question about the output of the sample program in section 1.5.3 Line Counting of K&R, Second Edition. Here's the program: /****************************************/...
14
by: jpr | last post by:
Friends, I have a form with four fields, date1, date2, date3 and date4. All these have all a mm/dd/yyyy format and have their source to a table. I need to add an unbound control (I will name...
4
by: dxsmith | last post by:
I'm new to Access and need some help if possible. I have a report that I'm trying to build from a table. The table lists students in a class. The table contains the usual fields such as name, class,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.