473,414 Members | 1,686 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,414 software developers and data experts.

Calculate data

759 512MB
Hello !

In a table I have a field "DataStart" As Date.
In the second field I wish to enter a period (i.e. 2 years). The field name is "Period".

The question is:
What format is required for the second field (Period) in order to calculate the EndData field ( EndData = DataStart + Period) in a query.

Thank you in advance !
Jul 7 '11 #1

✓ answered by NeoPa

The (Value) field could certainly be Long, but frankly an Integer field would convert automatically for the function call so could be used instead if required. I see no reason to use anything other than Long though.

7 1605
NeoPa
32,556 Expert Mod 16PB
Mihail,

I'm sure you don't need me to tell you that storing all three values in the record is not Normalised ==> a bad idea. Assume I just have.

Nevertheless, whether it is saved away or simply calculated for other uses, the question still makes sense so I will deal with it here :

It is possible for two date values to be added together to make a third date value (A + B = C). However, Not all of them would then be correctly displayable as dates in the way we normally expect (m/d/yyyy or d/m/yyyy depending on location). Consider A = today (7/7/2011) and B = 2 days. A + B = C would leave C as 9 July 2011 clearly. If you were to display A and B using a format of "d mmmm yyyy" the result for A would be "7 July 2011" whereas the result for B would be "1 January 1900". Clearly not as intended. The result for C would be fine too of course ("9 July 2011").

This rather overlooks the fact that days are simpler than other elements to add. Add 2 months today and the date will move on 62 days, yet do the same on 7 January 2011 and the move will be a mere 59 days. This is what the DateAdd() function can help you with. You specify the number and type of period to progress.

This means you must decide what you want your setup to support, and how to manage that. Clearly, if you want anyone to be able to select the type of period, as well as the number of such periods, then you will need to ensure you have a way of storing both pieces of information in your solution. That may be by storing it as a string, or by having two fields that do the individual jobs. Until you really know what you want to do there's not much point trying to answer this question in any more detail.
Jul 7 '11 #2
Mihail
759 512MB
Thank you for reply, NeoPa. My english is (again) too poor.
Please let me explain again, maybe better:
YES: In the table I have only two fields: DataStart (As Date) and Period. I wish to use this information to calculate the EndData (= StartData + Period).
But I don't know what type of data is required for Period field.
I think (but I am not sure) that the period can be Byte (in order to reduce the size of DataBase.
In this moment I don't know if period will be Month or Years. My client will decide that later. This is the reason I ask you: I wish to progress with my database until my client take a decision. Maybe, if I make a lot of tests, I can find the answer myself. But is more efficient (for me) to ask here instead to reinvent the warm water.
Jul 8 '11 #3
NeoPa
32,556 Expert Mod 16PB
If the client simply needs to tell you which type of period to include in the design then that is easily changed later on. If, on the other hand, they would need to choose on a per-item basis, then your design would need to handle them specifying both a value for the period as well as one for the type. This is a little more complex but fundamentally would follow along the same lines (using DateAdd()).
Jul 11 '11 #4
Mihail
759 512MB
Thnk you again NeoPa.
I understand from you that the field must be As Long (according with DateAdd() arguments).
Please confirm !
Jul 11 '11 #5
NeoPa
32,556 Expert Mod 16PB
The (Value) field could certainly be Long, but frankly an Integer field would convert automatically for the function call so could be used instead if required. I see no reason to use anything other than Long though.
Jul 11 '11 #6
Mihail
759 512MB
Thank you, NeoPa !
Jul 11 '11 #7
NeoPa
32,556 Expert Mod 16PB
A pleasure to help Mihail :-)
Jul 11 '11 #8

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

Similar topics

8
by: feel | last post by:
Hi, i need to read data from an Access Database. My problem is that all data have to be parsed or calculated so i'm looking for the fastest way. How to do that? Do i need a dataset or two...
13
by: apartain | last post by:
I searched the Help files and found that you can get around the #Error result when trying to calculate data from a subREPORT which has no data with the HasData property, but can not figure out how to...
13
by: kcddoorman | last post by:
In my form I have a text box. This textbox is not connected to the recordset that the rest of the form stores information in. I am using only to calculate data. I want to store that data in a field...
2
by: chris_huh | last post by:
I am doing a project on beetle diversity and need to calculate a few diversity indices for a load of data i have collected. I thought that maybe i could make a program in php to do that for, and...
2
by: sithynoan | last post by:
hi all. i want to calculate the number in a text box using c#,but i don know how to do.ex: when i input 254698 into a text box,i want to make calculation by adding the number one after another in...
2
by: taepy | last post by:
how can i calculate all the data that store in the database? if i wanna calculate it based on the date,what is the method that can i use?
8
by: muddasirmunir | last post by:
how can we calculate data at run time in crystal report 10 i had made three fields in my database name debit,credit , balance debit and credit shows data directly from database now i want a...
0
by: SuzK | last post by:
I am trying to calculate in VBA in Access 2002 a moving average and update a table with the calculations. Fields in my WeeklyData table are Week Ending (date) ItemNbr (double) Sales Dollars...
6
by: rrstudio2 | last post by:
I am using the following vba code to calculate the median of a table in MS Access: Public Function MedianOfRst(RstName As String, fldName As String) As Double 'This function will calculate the...
5
by: Big P | last post by:
Hello, I would like to calculate cells in DataGridView ( VB Express) My datagridview1 looks something like this. --------------------------------------… ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.