A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Datedif Expression



 
 
Thread Tools Display Modes
  #1  
Old February 1st, 2009, 05:54 PM posted to microsoft.public.access.gettingstarted
Don C
external usenet poster
 
Posts: 24
Default Datedif Expression

I have 3 entries on a form: TIME IN, TIME OUT, HOURS. In the TIME IN, I set
the Format as: Medium Time with an Input Mask for Medium Time. For TIME OUT,
I set the Format as: Medium Time with an Input Mask for Medium Time. For
HOURS, I set the Format as: Standard Number with this Control: Datedif(ā€œnā€
,[TIME IN],[TIME OUT])/60.

When I enter TIME IN as 12:00 AM (Mid Night), and TIME OUT as 07:30 AM, the
HOURS returns 7.5 which is right, but when I enter TIME IN as 07:30 PM, and
TIME OUT as 12:00 AM (Mid Night), the HOURS returns -19.5. It should be 4.5.
Also when I enter TIME IN as 12:00 AM and TIME OUT as 12:00 AM, I want HOURS
to return 24. This problem is confusing me. Can you help me?
--
Don C
  #2  
Old February 1st, 2009, 07:05 PM posted to microsoft.public.access.gettingstarted
Wayne-I-M
external usenet poster
 
Posts: 3,674
Default Datedif Expression

datediff will work fine - but you need to add the date or how will your
application know which day your using

12midnight to 12 midnight = 0 hours & 0 mins

but

12midnight today to 12 midnight tomorrow = 24 hours & 0 mins

The input masks and formats don't affect the data - just how it's entred and
seen.

May be an idea (to keep it simple) just to add an option group
Yesterday/today/tomorrow
but this may not be a good idea ?? as don't really understand your application

have a look at
http://www.mvps.org/access/datetime/date0008.htm
and
http://www.mvps.org/access/datetime/date0009.htm



--
Wayne
Trentino, Italia.



"Don C" wrote:

I have 3 entries on a form: TIME IN, TIME OUT, HOURS. In the TIME IN, I set
the Format as: Medium Time with an Input Mask for Medium Time. For TIME OUT,
I set the Format as: Medium Time with an Input Mask for Medium Time. For
HOURS, I set the Format as: Standard Number with this Control: Datedif(ā€œnā€
,[TIME IN],[TIME OUT])/60.

When I enter TIME IN as 12:00 AM (Mid Night), and TIME OUT as 07:30 AM, the
HOURS returns 7.5 which is right, but when I enter TIME IN as 07:30 PM, and
TIME OUT as 12:00 AM (Mid Night), the HOURS returns -19.5. It should be 4.5.
Also when I enter TIME IN as 12:00 AM and TIME OUT as 12:00 AM, I want HOURS
to return 24. This problem is confusing me. Can you help me?
--
Don C

  #3  
Old February 1st, 2009, 10:42 PM posted to microsoft.public.access.gettingstarted
Linq Adams via AccessMonster.com
external usenet poster
 
Posts: 1,474
Default Datedif Expression

This code checks for the situation you describe and makes an adjustment to
the DateDiff() results if the condition exists.

If StopTime = StartTime Then
Me.TimeInMinutes = DateDiff("n", StartTime, StopTime) + 1440
Else
Me.TimeInMinutes = DateDiff("n", StartTime, StopTime)
End If

You can then parse the results into hours using

/60

if you wish. Having said this, it really is preferable when recording time to
include the date portion.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via http://www.accessmonster.com

 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:05 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.