Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Categories

Status
Not open for further replies.

lcfc

Programmer
Dec 4, 2001
27
GB
Can anybody tell me how i can put times into categories? I need a macro that will put a time in a category say if it between 00:01 and 01:00 or 01:01-02:00, etc. Is this possible?
 
lcfc,

First, you must understand what Time values are. Time is part of Date. Dates and Times are just NUMBERS, like the Date/Time value right now is 38189.28032. The DATE part is the Integral part of the number and the TIME part is the Fractional part of the number. Bottom line -- Time is in Fractions of a Day. MS Applications have a Format function that can DISPLAY the Date/Time value in any number of ways using
[tt]
Format(Now, "dddd mmmm d, yyyy hh:mm:ss")
[/tt]
on 38189.28032 displays Wednesday July 21, 2004 06:43:40
or, if you wanted to just display time...
[tt]
Format(Now, "h:mm")
[/tt]
6:43

Now for your question. It all depends what you want to do with these time ranges. For instance
Code:
Select Case Format(tStart, "hh:mm")
  Case Is <= "01:00"
'stuff to do in this time slot
  Case Is <= "02:00"
'stuff to do in this time slot

'etc
End Select



Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
If you want to assign times to "hour bins", then you can do that with a simple worksheet formula:
=INT(24*(A1-INT(A1)))
A1 contains a date/time serial number, as explained by Skip. This formula will return 2 for all times between 2:00 and 2:59:59999999

If you want the "hour bins" to start at 1 minute past the hour, then the formula becomes:
=INT(24*(A1-INT(A1)-1/1440))
There are 1440 minutes per day, thus explaining the 1/1440 part of the formula
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top