Re: Sum not recoginzing a negative number
From: Allen Browne (AllenBrowne_at_SeeSig.Invalid)
Date: 12/06/04
- Next message: Al Kaufman: "pdf--insert into report"
- Previous message: Bobk: "Sum not recoginzing a negative number"
- In reply to: Bobk: "Sum not recoginzing a negative number"
- Next in thread: Bobk: "Re: Sum not recoginzing a negative number"
- Reply: Bobk: "Re: Sum not recoginzing a negative number"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 6 Dec 2004 22:02:01 +0800
You cannot use normal floating point math with date/time values.
Open the Immediate window (Ctrl+G), and enter:
? CDate(0.25)
As expected, a quarter of a day is 6am - actually 6am on Dec 30 1899.
So what would you expect from:
? CDate(-0.25)
Would you expect that to be 6pm on the day before?
It may surpris you to learn that it is 6am on Dec 30 1899 also.
The reason is that date/time values are defined like this:
- the integer part represents the date, and
- the fraction part represents the time.
In the example above, the zero represents the date (Dec 30, 1899), and the
0.25 represents the time. Applying the same logic to -0.25, the -0
represents the date, and the 0.25 represents the time. Since 0 is the same
as -1, the date is the same. And since 0.25 is the same in both cases, 0.25
and -0.25 both represent the same date and time.
The upshot is that you should always use the built-in functions such as
DateDiff() when working with dates and times. Normal floating-point math
does not apply.
-- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Bobk" <Bobk@discussions.microsoft.com> wrote in message news:D72B7100-0AFD-448D-AA3A-C0A45B3E3009@microsoft.com... >I have a report in which I am attempting to calculate elapsed time. One >being > the start of work on a job, the second being the completion of the job. > The > start time and the end time are entered through a form which creates a > record > for each event. In my report I group the two events by day and sum them > using > the sum function. In order to force subtraction (subtracting the starting > time from the ending time) I multiply the beginning time by -1 which > results > in a minus number. When the report adds the two it does not recognize the > negative number and sums them together as if they were both positive. I > use > the following routine to calculate the negative value: IIf([Start]="Y", > ((CDbl([Trak_Date_Time]))*-1), CDbl([Trak_Date_Time])) > Where: Trak_Date_Time is date/time. I use CDbl to convert date/time to a > double precision value and multiply by minus 1 to get a negative number > for > the stating time.If I manually subtract the converted sarting time from > the > end time I get the correct elapsed time. On my report the the end time > appears as a positive and the start time appears as a -. Summing the two > should result in elapsed time. Sum does not recognize the negative value > and > adds both together disregarding the minus sign. I'm at a loss. Anyone have > a > suggestion?
- Next message: Al Kaufman: "pdf--insert into report"
- Previous message: Bobk: "Sum not recoginzing a negative number"
- In reply to: Bobk: "Sum not recoginzing a negative number"
- Next in thread: Bobk: "Re: Sum not recoginzing a negative number"
- Reply: Bobk: "Re: Sum not recoginzing a negative number"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|