Group:  Microsoft Access ยป microsoft.public.access.gettingstarted
Thread: Expression in Query

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Expression in Query
Rob <krekmek[ at ]hotmail.com> 18.07.2006 08:36:37
A question about Expressions in Queries.

I work flexible hours and want to use Access to find out if I have
worked too long (> 8:30) or too short (<8:30) on a given day.

My simple table has three fields:
EnterOffice (e.g. value 8:15 AM)
LeaveOffice (e.g. value 3:40 PM)
StandardTime (value 8:30)

In a Query I have this Expression:
LeaveOffice - EnterOffice - StandardTime

The result = 1:05 whereas I would have liked to get -1:05, in other
words: the outcome seems to be an absolute number.

Any solutions?
Thanks - Rob
Re: Expression in Query
"Jeff Boyce" <JeffBoyce_IF[ at ]msn.com-DISCARD_HYPHEN_TO_END> 18.07.2006 12:22:42
Rob

What data type are your fields? Are they Date/Time? Are you only storing a
time value (you might not realize it, but you ARE storing a date portion
too)?

How are you finding the difference? Are you using a query and the
DateDiff() function?

How are you getting an hh:mm-formatted result? Are you starting with
minutes and "parsing" that into hh:mm?

--
More info, please ...

Jeff Boyce
Microsoft Office/Access MVP
http://mvp.support.microsoft.com/

Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Microsoft Registered Partner
https://partner.microsoft.com/


"Rob" <krekmek[ at ]hotmail.com> wrote in message
news:u$oBKVkqGHA.5108[ at ]TK2MSFTNGP05.phx.gbl...
[Quoted Text]
> A question about Expressions in Queries.
>
> I work flexible hours and want to use Access to find out if I have
> worked too long (> 8:30) or too short (<8:30) on a given day.
>
> My simple table has three fields:
> EnterOffice (e.g. value 8:15 AM)
> LeaveOffice (e.g. value 3:40 PM)
> StandardTime (value 8:30)
>
> In a Query I have this Expression:
> LeaveOffice - EnterOffice - StandardTime
>
> The result = 1:05 whereas I would have liked to get -1:05, in other
> words: the outcome seems to be an absolute number.
>
> Any solutions?
> Thanks - Rob

Re: Expression in Query
"John Spencer" <spencer[ at ]chpdm.edu> 18.07.2006 12:47:17
Time comes in two flavors - elapsed duration (I worked 3 hours) and instant
in time (It is 3 AM). Your calculation ends up giving you an instant in
time (which is never negative).

I would try using the DateDiff function to convert your Start time and End
time into a duration and then subtract that to get number minutes over or
under.

DateDiff("n",LeaveOffice,EnterOffice) - 510 will give you the number of
minutes over or under a duration of 8 hours and 30 minutes.

If StandardTime is a date field and varies you can use
DateDiff("n",StandardTime,0) to get the minutes

DateDiff("n",LeaveOffice,EnterOffice) - DateDiff("n",StandardTime,0)

To Format that nicely into hours and minutes and get a negative sign,
requires a bit of arithmetic and formatting. Replace X with the formula of
choice above

IIF(X<0,"-","") & ABS(X\60) & Format(ABS(X Mod 60),"\:00")

"Rob" <krekmek[ at ]hotmail.com> wrote in message
news:u$oBKVkqGHA.5108[ at ]TK2MSFTNGP05.phx.gbl...
[Quoted Text]
>A question about Expressions in Queries.
>
> I work flexible hours and want to use Access to find out if I have worked
> too long (> 8:30) or too short (<8:30) on a given day.
>
> My simple table has three fields:
> EnterOffice (e.g. value 8:15 AM)
> LeaveOffice (e.g. value 3:40 PM)
> StandardTime (value 8:30)
>
> In a Query I have this Expression:
> LeaveOffice - EnterOffice - StandardTime
>
> The result = 1:05 whereas I would have liked to get -1:05, in other words:
> the outcome seems to be an absolute number.
>
> Any solutions?
> Thanks - Rob


Re: Expression in Query
Rob <krekmek[ at ]hotmail.com> 18.07.2006 19:51:50
John Spencer wrote:
[Quoted Text]
> Time comes in two flavors - elapsed duration (I worked 3 hours) and instant
> in time (It is 3 AM). Your calculation ends up giving you an instant in
> time (which is never negative).
>
> I would try using the DateDiff function to convert your Start time and End
> time into a duration and then subtract that to get number minutes over or
> under.
>
> DateDiff("n",LeaveOffice,EnterOffice) - 510 will give you the number of
> minutes over or under a duration of 8 hours and 30 minutes.
>
> If StandardTime is a date field and varies you can use
> DateDiff("n",StandardTime,0) to get the minutes
>
> DateDiff("n",LeaveOffice,EnterOffice) - DateDiff("n",StandardTime,0)
>
> To Format that nicely into hours and minutes and get a negative sign,
> requires a bit of arithmetic and formatting. Replace X with the formula of
> choice above
>
> IIF(X<0,"-","") & ABS(X\60) & Format(ABS(X Mod 60),"\:00")

Thanks guys,

I was looking for a simple solution. My trainees try to solve this in
Excel but in the "1900" (as opposed to 1904) Date mode, negative times
are presented as #####

In Windows Excel enter:
A1 = 7:55
A2 = 8:00

In A3 formula = A1-A2

Result = #####

Removing formatting however shows a negative number.
If you switch to the "1904" date system, you're all set.

I know how to cope with this but I was looking for a comprehensable
solution to show my trainees.

Yes, I used Date/Time fields.

Have solved this in FileMaker but as most people who attend my courses
use Microsoft Office, I was trying to find a substitute for Excel in Access.

Thanks again - Robert

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net