473,486 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

date difference calculation

8 New Member
im not sure how to even start this. im using access 03 to build a db to store my water district meter readings. i have 2 tables so far, 1 consumer info and 2 monthly meter readings. i need a query to bring up the difference between current month meter reading and last months meter reading for each consumer. thats where im stuck because ive never used access to do much of anything at all. so i figured id ask, and here i am. table 1 consumer info doesnt store much except name and address. i may add more info later if needed. table 2 is where the usefull information is stored. it has consumer name, date and meter reading. what i am trying to figure out is how to get the difference between monthly meter readings so i can make a report that will print up a bill to send out to the consumers. first i need the difference then i can try to get access to calculate the bills cost. just trying to make things more user friendly on my part. thanks in advance.
Jul 23 '07 #1
15 3297
sumhungl0
8 New Member
maybe i need a table for each consumer?
Jul 23 '07 #2
Ares6881
20 New Member
im not sure how to even start this. im using access 03 to build a db to store my water district meter readings. i have 2 tables so far, 1 consumer info and 2 monthly meter readings. i need a query to bring up the difference between current month meter reading and last months meter reading for each consumer. thats where im stuck because ive never used access to do much of anything at all. so i figured id ask, and here i am. table 1 consumer info doesnt store much except name and address. i may add more info later if needed. table 2 is where the usefull information is stored. it has consumer name, date and meter reading. what i am trying to figure out is how to get the difference between monthly meter readings so i can make a report that will print up a bill to send out to the consumers. first i need the difference then i can try to get access to calculate the bills cost. just trying to make things more user friendly on my part. thanks in advance.
You don't need a table for each consumer, dealing with dates can be pretty tricky especially when it comes to year changes. I take it you want to deal directly with months and not days? Days can be a bit easier when dealing with date ranges, but months is still possible. Start off making a query that gets the sum of all your bills for the current month, but in your consumer name as one of your columns, then have it sum up your meter readings in another column and in the last column put the month of your date field, I believe you can use the datepart function to get that. That should get you your first step, sorry I can't get you any more right now, but it's lunch time ;P
Jul 23 '07 #3
sumhungl0
8 New Member
well im gonna try a few things. but the meter reading is done monthly. so i only have one meter reading per consumer per month. so thats why i thought i would make a table for each consumer, what do you think? my date column is in the format of mmddyyy just for ease, but the month is all im looking for. i work with an older lady on this part in which her only job on this deal is to input the monthly meter readings for the consumers. we do not get paid for this. im just trying to make things easier on us in the long run. in the end, the only info that gets put in monthly is the meter reading and month for each consumer. i need this db to give me the difference between the reading from the current month and the last month. then ill try to figure out how to make the db calculate the bill and print it from a report. that way i am not doing all this on a calculator and word document. does that clear things up a bit?
Jul 24 '07 #4
Ares6881
20 New Member
well im gonna try a few things. but the meter reading is done monthly. so i only have one meter reading per consumer per month. so thats why i thought i would make a table for each consumer, what do you think? my date column is in the format of mmddyyy just for ease, but the month is all im looking for. i work with an older lady on this part in which her only job on this deal is to input the monthly meter readings for the consumers. we do not get paid for this. im just trying to make things easier on us in the long run. in the end, the only info that gets put in monthly is the meter reading and month for each consumer. i need this db to give me the difference between the reading from the current month and the last month. then ill try to figure out how to make the db calculate the bill and print it from a report. that way i am not doing all this on a calculator and word document. does that clear things up a bit?
Is the date column set as a date value, or is it a number value with mmddyyy (only 3 y for year? or was that a mistype?) as the format. If it's just a number value it's handled a bit differently. If you don't know how to tell go to the table and go into design view, it should tell you on the right hand side what kind of value it is. Could you give me the names of each column so I can make queries that you can just plug in? Are the readings always done on the same day every month, or does it change? Were you able to figure out the datepart function (this doesn't work if it's a number value)?
Jul 24 '07 #5
sumhungl0
8 New Member
Is the date column set as a date value, or is it a number value with mmddyyy (only 3 y for year? or was that a mistype?) as the format. If it's just a number value it's handled a bit differently. If you don't know how to tell go to the table and go into design view, it should tell you on the right hand side what kind of value it is. Could you give me the names of each column so I can make queries that you can just plug in? Are the readings always done on the same day every month, or does it change? Were you able to figure out the datepart function (this doesn't work if it's a number value)?
ok as for the date question....
i dont care what format it is i can change it to whatever you suggest, because all i need for the date is that it happens once monthly. we have a guy who goes around my small town and takes water meter readings. the data is input into a excell spreadsheet right now. it only needs to be input monthly, so i dont care what format it is in the end. i just thought it would be better to use the full date format. and yes i mistyped... sorry. i could even make it into a dropdown list to pick the month if need be, but i didnt know how to do the year because i wanted the db to keep history.

the names of the columns are....
consumer name / date / meter reading
thats it, thats really all i need from that table. that data is the only info taken from consumer homes. then i need to know the difference between meter readings to find water usage. then i can calculate the bill on that difference. does that help?
Jul 24 '07 #6
Ares6881
20 New Member
ok as for the date question....
i dont care what format it is i can change it to whatever you suggest, because all i need for the date is that it happens once monthly. we have a guy who goes around my small town and takes water meter readings. the data is input into a excell spreadsheet right now. it only needs to be input monthly, so i dont care what format it is in the end. i just thought it would be better to use the full date format. and yes i mistyped... sorry. i could even make it into a dropdown list to pick the month if need be, but i didnt know how to do the year because i wanted the db to keep history.

the names of the columns are....
consumer name / date / meter reading
thats it, thats really all i need from that table. that data is the only info taken from consumer homes. then i need to know the difference between meter readings to find water usage. then i can calculate the bill on that difference. does that help?
Yeah, that helps, alrighty one neat trick in case you didn't already know how to do it is that you can actually import from your excel sheet directly into access. It's under file/get external data/import
You'll then select Microsoft Excel from the type at the bottom then pick your file. Your file should be in the format of having your headers across the top and all your data below it to import properly. You may want to change your date header to say something other than date as date can be used as a function in access and you don't want to confuse the two. Anyway, that should save you time on data entry.

Back to your query, once you have your table made start making your query of the new table. The columns should be something like this:

consumer name / meter reading / ReadMonth: Format([dateread],"yyyymm")
This will give you your customer's name, what the meter reading was, and a number that represents the year and month, for instance for todays date it would be 200707

Under your criteria for ReadMonth you want to put this:

Between IIf(Format(Date(),"mm")="01",Format(Date(),"yyyymm ")-89,Format(Date(),"yyyymm")-1) And Format(Date(),"yyyymm")

I've tested this and it should work (this actually helped me work out some stuff with my own databases ;) ) Here's how it works, the way Between works is like this:
Between [First Number] And [Second Number]

Then in order to calculate the first number we first off make sure that it isn't january, if it is the first number is the numerical version of todays date minus 89, if it isn't January then it's only minus one. the IIf statement determines this for you:

IIf([condition], [if condition is true], [if condition is false])

the final bit just gets todays numerical value for this month, like I said earlier for today it would be 200707

So, here's how it goes with some actual data, say it's January 2008 the first thing it does is it sees if it's January, it is so it does the numerical value 200801, subtracts 89 from it which should be 200712 and then it calculates the current months value, which is 200801 then it enters both numbers in the between, so it comes up with all numbers between 200712 and 200801. This should get all your records in December 2007 and January 2008.

This should work as long as you run it during the month you're calculating, the Date() is always your computer's date. Anyway, hope that isn't too overwhelming, let me know if you have any questions.
Jul 24 '07 #7
sumhungl0
8 New Member
this is very interesting. i read through everything and ill give it a shot come brake time. thank you very much for the help and teaching me a bit. ill give it a shot shortly and ill post again. thanks for your help....
Jul 25 '07 #8
Boxcar74
42 New Member
Not 100% sure what you are looking for

Do you want the results like this:

Example: Columns Headings
Customer, JAN, FEB , MAR, etc.....

With the monthly totals on the grid for each month.

Like :
Joe S , 100202, 102020, 192837, etc...

If so, a simple Crosstab Query will do this.
The Wizard will walk you though it.
But since you are new I'll ad some info.

1. in the queries section press new, select Crosstab Query Wizard.
2. Select the table you want and the Fields for rows. Like Customer.
3. Select Columns heading. Date
4. NEXT tab Select MONTH
5. Then pick the data you want in the grid, Meter reading, I think have to sum them. It should affect the total.

I hope this helps.

If this is how you want it and need to add field from the customer info table that can be easily done in the design view.

Try it, and I'll check back.

-- Boxcar
Jul 25 '07 #9
Boxcar74
42 New Member
Also since your DB isn't extremely complicted you might want to look at templates for examples.

Microsoft has some at:
http://office.microsoft.com/en-us/te...3&CTT=6&av=ZAC

But there are plenty out there.

I'm sure they done have one to fit your needs but you probably find one to serve as a guide.

Especially for the reports/invoices, if you are going ot have calculations in them.

Hope this helps!

-- Boxcar
Jul 26 '07 #10
sumhungl0
8 New Member
ares
i dont think im getting the format date thingy right. says "data type mismatch in criteria expression". this is what i have in criteria under readmonth:
Expand|Select|Wrap|Line Numbers
  1. Between IIf(Format(Date(),"mm")="01",Format(Date(),"yyyymm")-89,Format(Date(),"yyyymm")-1) And Format(Date(),"yyyymm")
know what that means?

boxcar
Do you want the results like this:

Example: Columns Headings
Customer, JAN, FEB , MAR, etc.....

With the monthly totals on the grid for each month.

Like :
Joe S , 100202, 102020, 192837, etc...
that would work perfect. but would i need to put in a new month column in monthly, or 12 yearly or can a column be created automaticly when putting in the meter readings?
Jul 26 '07 #11
sumhungl0
8 New Member
i did get the date format yyyymm to work by just typing yyyymm into the format box of column readmonth in my table called "monthly meter readings". that part worked perfect like you said. date shows up as 200701.
Jul 26 '07 #12
Boxcar74
42 New Member
The 12 Monthly Columns are automatically created in the Crosstab Query Wizard. They list as JAN, FEB, MAR, etc......


With the formats yyyymm you can use "yyyy/mm" or "mm/yyyyy"
How ever you want it formated.

The Crosstab automatically does it as "mmm" Ex: Jan, Feb, etc... you can change the format however you want i.e yyymm in the SQL text but is kind of a pain.

In the SQL view It is display as:
PIVOT Format([Date],"mmm") In ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug"," Sep","Oct","Nov","Dec");

So it you go this route you and want to change the format you need to manually edit Each month there.
EX: PIVOT Format([OPEN_Date],"yyyy/mm") In ("2007/01","2007/02" etc...

Also
"mmm/yyyyy" displays as Jan/2007 and so on.
"mmmm" displays as January
and "mmmm/yyyyy" as January/2007
I think you got the point.

I'd stick with JAN, FEB....

Anyway Good Luck !!

-Boxcar
Jul 26 '07 #13
sumhungl0
8 New Member
i need to think back to what data i need from this db and figure the best way to setup my tables. i dont know how i can do my meter readings table having months keep going. i would have a new column for every month. or i could have a column for all 70 something consumers. i cant figure out which would be best. any advise on this?
Jul 30 '07 #14
Boxcar74
42 New Member
I think you tables are fine.

I would run a crosstab query off the table with
consumer name / date / meter reading

Having "Consumer name" as the Row Heading, "Date" as the Column heading and "meter reading" as the value (use sum), it will just give you the Customer total.

Then run a query off of that to find the monthly differance.
IT should be something like: Expr1: [query1].[JAN]-[query1].[FEB]= Differance. But that is a crude example.

I'll get back to you on that one I want to check the format to use.

BTW -- How many months are we talking about?

-- Boxcar
Jul 30 '07 #15
Ares6881
20 New Member
He was comparing the current month to last month I believe, anyway, sorry for my absence, work and all.

Not sure why the criteria didn't work for you, what it sounds like to me is that for some reason the data that you have in that column may somehow be incompatible, but you already said that it displays properly. Let me know what your tables look like and I'll see if I can't figure out what's going on.
Aug 6 '07 #16

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

Similar topics

4
10075
by: Manny Chohan | last post by:
Hi Can anyone tell me how i can calculate yesterday date using asp? Thanks manny
4
5340
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
4
2626
by: qtip | last post by:
I have a simple table the has First Name , Last Name, SSN, Date&Time. I have a report that will show all this information but I would like to put in at calculation to tell the difference between 2...
2
2377
by: Gershon | last post by:
I have a simple table including First Name, Last Name, Start Date. I need to create a report listing First, Last and the number of days since Start Date. The First and Last names are easy. How do I...
2
1397
by: Issac Gomez | last post by:
IN VB.Net, you can use the DateDiff method to calculate the difference between 2 days. How do you do this in C#? I want to find the number of days between 2 dates. I there a 0 days, then I want to...
3
7455
by: Reney | last post by:
I am using Access in my project. In one of the forms, I am calling two tables, and two of the columns have date/time type, namely "ClockIn" and "ClockOut". I created a dataset and filled the...
4
15653
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
10
16947
by: DontellTrevell via AccessMonster.com | last post by:
HELP!!....I need to calculate the numer of days elapsed between two field. But, the date format is YYYYMMDD. How can i accomplsh this? -- Dontell Trevell Message posted via AccessMonster.com...
6
8993
by: krishnakant Mane | last post by:
hello, I am strangely confused with a date calculation problem. the point is that I want to calculate difference in two dates in days. there are two aspects to this problem. firstly, I can't get...
0
7123
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
7173
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...
1
6839
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7305
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5427
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3066
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.