Is there any chance of changing the struture so you have these fields
instead:
StartDateTime Date/Time both the date and time
Minutes Number duration in minutes
If you store the data in those 2 fields, you can use a query to derive
anything else you want, by typing an expression into the Field row in
query design. For example, to get the day of the week:
DOW: Weekday([StartDateTime])
To get the ending date and time:
EndDateTime: DateAdd("n", [Minutes], [StartDateTime])
To get the start time only:
StartTime: TimeValue([StartDateTime])
Do you see that you can then use expressions such as those to calculate
anything else you want to do.
If that is not practical, you will have to derive those expressions from
the fields you have. This kind of thing (untested example only):
Minutes: IIf(([EndDay] = [StartDay]) And ([EndTime] > [StartTime]),
DateDiff("n", [StartTime], [EndTime]),
IIf(([EndDay] = [StartDay] + 1) And ([EndTime] < [StartTime]),
DateDiff("n", [StartTime], [EndTime] + 1),
0))
More info:
Calculating elapsed time
at:
http://allenbrowne.com/casu-13.html
And if you are thinking about the interface, you can design that so the
user enters the data any way you want, and behind the scenes your code
combines the start date and time, and calculates the number of minutes to
store. Ultimately, the way the user enters the data and the way you need
to store it are quite different things.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Reply to group, rather than allenbrowne at mvps dot org.
DS said:
Thanks Allen , I see this something that I'll have to play with! The
problem is that it doesn't go by date I have to go by Day 1 to 7 and the
time...
I have a form that contains data and the problem I'm having is if I have
a dinner menu that starts on Monday at 5:00 PM and ends at 1:00 AM
Tuesday morning it doesnt come up because Monday is day 2 and Tuesday is
day 3.
So I was thinking of perhaps this...
Start Day Monday(2) Start Time 5:00PM
EndDay Tuesday(3) End Time 1:00AM
So how would I query this?
StartDay =< Now() and StartTime > Time()
EndDay = Now() and EndTime < Time()
Thanks Allen
DS