Subtracting Hours

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I programatically find out how many hours are in each month?

Thanks for any ideas!
 
This depends on the year since February varies. If you have fields or
expressions named Yr and Mth, you could use someting like:

DateDiff("d",DateSerial(Yr,Mth,0),DateSerial(Yr,Mth+1,0)) * 24
 
How can I programatically find out how many hours are in each month?

Thanks for any ideas!

Since the number of days in February can vary every fourth year, this
should work to give the resulting number of hours per current month.

= Day(DateSerial(Year(Date()),Month(Date()) + 1,0))*24

For July the result is 744 .
 
Duane,

I have the further complexity of Daylight Savings Time. Not every day has
24 hours during the year. How can I work around DST?

Thanks,
Cathy
 
I like Fred's calc since it is shorter. I would write a small function that
accepts the month and year (or a date) and returns -1, 0, 1 based on if an
hour is removed, added, or no effect.

There is information on the dates for the U.S. and Europe at
http://webexhibits.org/daylightsaving/b.html.
 
I figured it out!

SELECT
tblDates.Start_Date,
tblDates.End_Date,
(DateDiff('d',[End_Date],[Start_Date])-1)*-1 AS Days,
IIf((DatePart("m",tblDates.Start_Date)=4),(Days*24)-1,IIf((DatePart("m",tblDates.Start_Date)=10),(Days*24)+1,(Days*24))) AS Hours
FROM tblDates;

Thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top