PC Review


Reply
Thread Tools Rate Thread

DateDiff Function

 
 
Joanne
Guest
Posts: n/a
 
      18th Jun 2009
Hello,
I have the following in a query field and I'm getting a strange result:
Iif ([Type Of Day]="Personal" or [Type of Day]="Jury Duty" Or [Type of
Day]="Carryover", "0",DateDiff("h",[OLP Begin Date],[OLP End Date]/24))

The purpose of the query is to get a return for 1/2 vacation days, but it's
returning things like -908315 for one vacation day. I thought I was doing
this right, but obviously I'm not.

Thank you very much for any help you can provide.
 
Reply With Quote
 
 
 
 
John Spencer MVP
Guest
Posts: n/a
 
      18th Jun 2009
Perhaps what you want is the following.

Iif ([Type Of Day] IN ("Personal","Jury Duty","Carryover"),
0,DateDiff("h",[OLP Begin Date],[OLP End Date])/24)


One problem is that your statement was dividing the end date by 24 before
calculating the number of hours between the Begin date and the end date. I'm
not sure you are going to get the desired result anyway, since I don't know
that the Begin date and End date contain a date and a time (other than the
default midnight).


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Joanne wrote:
> Hello,
> I have the following in a query field and I'm getting a strange result:
> Iif ([Type Of Day]="Personal" or [Type of Day]="Jury Duty" Or [Type of
> Day]="Carryover", "0",DateDiff("h",[OLP Begin Date],[OLP End Date]/24))
>
> The purpose of the query is to get a return for 1/2 vacation days, but it's
> returning things like -908315 for one vacation day. I thought I was doing
> this right, but obviously I'm not.
>
> Thank you very much for any help you can provide.

 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      18th Jun 2009
On Thu, 18 Jun 2009 11:56:02 -0700, Joanne <(E-Mail Removed)>
wrote:

>Hello,
>I have the following in a query field and I'm getting a strange result:
>Iif ([Type Of Day]="Personal" or [Type of Day]="Jury Duty" Or [Type of
>Day]="Carryover", "0",DateDiff("h",[OLP Begin Date],[OLP End Date]/24))
>
>The purpose of the query is to get a return for 1/2 vacation days, but it's
>returning things like -908315 for one vacation day. I thought I was doing
>this right, but obviously I'm not.
>
>Thank you very much for any help you can provide.


You're dividing the OLP End Date by 24 - that'll give you a date sometime in
1904, because of the way dates are stored!

I think it's just a misplaced parenthesis: try

Iif ([Type Of Day]="Personal" or [Type of Day]="Jury Duty" Or [Type of
Day]="Carryover", 0 ,DateDiff("h",[OLP Begin Date],[OLP End Date])/24)

Note that I'm using a numeric 0 rather than a text string "0" since DateDiff
returns a number, and they should match.

Hmmmm... thinking about it... this will give the duration in twenty-fourths of
an hour, which is probably not what you want. What SHOULD the result contain?
Days? Days in half-day increments? hours?

--

John W. Vinson [MVP]
 
Reply With Quote
 
Joanne
Guest
Posts: n/a
 
      18th Jun 2009
Thank you very much. It now returns a value in days and, you were right, it
isn't giving me the 1/2 day, but at least it works! Thanks again.

"John Spencer MVP" wrote:

> Perhaps what you want is the following.
>
> Iif ([Type Of Day] IN ("Personal","Jury Duty","Carryover"),
> 0,DateDiff("h",[OLP Begin Date],[OLP End Date])/24)
>
>
> One problem is that your statement was dividing the end date by 24 before
> calculating the number of hours between the Begin date and the end date. I'm
> not sure you are going to get the desired result anyway, since I don't know
> that the Begin date and End date contain a date and a time (other than the
> default midnight).
>
>
> John Spencer
> Access MVP 2002-2005, 2007-2009
> The Hilltop Institute
> University of Maryland Baltimore County
>
> Joanne wrote:
> > Hello,
> > I have the following in a query field and I'm getting a strange result:
> > Iif ([Type Of Day]="Personal" or [Type of Day]="Jury Duty" Or [Type of
> > Day]="Carryover", "0",DateDiff("h",[OLP Begin Date],[OLP End Date]/24))
> >
> > The purpose of the query is to get a return for 1/2 vacation days, but it's
> > returning things like -908315 for one vacation day. I thought I was doing
> > this right, but obviously I'm not.
> >
> > Thank you very much for any help you can provide.

>

 
Reply With Quote
 
Joanne
Guest
Posts: n/a
 
      18th Jun 2009
Hello,
Many thanks for the help. The result I'm trying to get is in days, which is
working, but there are times when an employee wants to take only 1/2 day, so
I thought I would enter the datediff in hours but that didn't work either. I
need to have it displayed as 1.5 days or 2.5 days, or whole days, if that's
possible. Part of the problem is that the employeee might take all of Tuesday
and then only half of Wed. Ugh.

"JimBurke via AccessMonster.com" wrote:

> Are you simply trying to translate the number of 'off days' into a number of
> half-days? e.g. if they had 2 days off, you want to return 4 half-days? if
> that's the case, I would think you would just calculate the number of days
> off using datediff and then multiply that by 2. Maybe I'm misinterpreting the
> purpose of the query.
>
> Joanne wrote:
> >Hello,
> >I have the following in a query field and I'm getting a strange result:
> >Iif ([Type Of Day]="Personal" or [Type of Day]="Jury Duty" Or [Type of
> >Day]="Carryover", "0",DateDiff("h",[OLP Begin Date],[OLP End Date]/24))
> >
> >The purpose of the query is to get a return for 1/2 vacation days, but it's
> >returning things like -908315 for one vacation day. I thought I was doing
> >this right, but obviously I'm not.
> >
> >Thank you very much for any help you can provide.

>
> --
> Jim Burke
>
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/For...dules/200906/1
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Datediff function =?Utf-8?B?QWxleCBXb29kaGFtcw==?= Microsoft Access Forms 5 24th Aug 2007 10:07 PM
need help on DateDiff function! Learner Microsoft VB .NET 5 16th Feb 2006 07:54 PM
Datediff Function MN via AccessMonster.com Microsoft Access Queries 5 9th May 2005 12:37 PM
Using the DateDiff function =?Utf-8?B?S0xGaXR6?= Microsoft Access Reports 1 15th Oct 2004 04:55 AM
DateDiff function Lauren Microsoft Access 5 31st Oct 2003 08:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:50 AM.