473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Assign a numeric value to a time range?

I have a database that I created for logging Calls for Service for a Security Department I work for.

In that database it logs the Date of Entry [EntryDate] and Time of Entry [EntryTime]. For statistical purposes I would like to be able to assign a numeric value to certain time ranges.

Such as;
07:00 - 14:59 = 1
15:00 - 22:59 = 2
23:00 - 06:59 = 3

I cannot figure out how to do this though. Any help would be appreciated.
May 7 '09 #1
13 3627
FishVal
2,653 Expert 2GB
Hello.

Create a table with a structure like the following:

Expand|Select|Wrap|Line Numbers
  1. lngKeyRangeNum    Long, PK
  2. dteStart                 Date
  3. dteEnd                  Date
  4.  
I guess the question is not about "assignment", but how to practically use it.
So, how do you intend to use it?

Regards,
Fish
May 7 '09 #2
I have the table and I'm sorry if what I state above didn't make any sense , but truth be told I don't know how to explain it.

What I'm looking for/to do is that if I enter an in item into the table either by query/vba/form etc it will assign a numeric value to the entry based on what time the item was entered. That numeric value is determined by the ranges I listed above.

What it is , is the database tracks the calls for service we recieve at our Security Department. Those calls come in at all times of the day , and we operate 24/7 on a 3 shift assignment, 1st shift is 0700 to 1459, 2nd is 1500 - 2259 and 3rd is 2300 - 0700. I'm trying to determine a way to assign the call to the shift based on what time the call was entered.
May 7 '09 #3
FishVal
2,653 Expert 2GB
Well.

There is no need to store additional number in the table where time is stored since conversion rules are "stored" in the table which I've suggested you to add to your database.
Read please a very similar thread - Grouping Query Range.

Also, I guess you will benefit from reading the following articles:
Database Normalization and Table Structures
SQL JOINs

Regards,
Fish
May 7 '09 #4
OldBirdman
675 512MB
This doesn't need another table or a new field. It is a calculated value:
Expand|Select|Wrap|Line Numbers
  1. (Int(((Hour(#<Your Time Or Date Here>#)-7)+24) Mod 24) / 8 ) + 1 
I would store the actual time, and convert to the 1..2..3 format when needed. This way the precise data remains available if needed in the future
May 7 '09 #5
FishVal
2,653 Expert 2GB
Exelltnt point, OldBirdman.

However, this approach lacks of flexibility. Though it gives a more simple solution, it is not suitable for future or temporary changes which should be foreseen even when they are not expected...

.... I would say: especially when they are not expected ;)

Regards,
Fish

P.S. Something tells me that the table storing shift times is not unnecessary in more or less comprehensive database.
May 7 '09 #6
OldBirdman
675 512MB
The "Grouping Query Range" reference isn't exactly straightforward either, and would present another programmer some effort if the program had to be modified in the future.
Keeping it simple, maybe create a table with 24 records, one for each hour.
tblShiftNumber
Expand|Select|Wrap|Line Numbers
  1. ShiftHr (PK)  ShiftValue
  2.      0          3
  3.      1          3
  4.      2          3
  5.     ...
  6.      7          1
  7.      8          1
  8.      14         1
  9.     ...
  10.      15         2
  11.     ...
  12.      23         2
This would make the SELECT query a simple join on Hour([LoggedTime]), would be easy to correct by programmer or a simple form, and meet requirements.
In my part of the world, shifts are not always equal length, the day(normal) shift running between 8AM-5PM with 1 hour off for lunch (staggered if coverage required). 2nd shift 5PM-Midnight and 3rd Midnight-8AM.
Above table could be expanded to 1/2 hour increments (or 1/4 hour) if needed by using Int(Minutes([LoggedTime]) / 30) to build the ShiftHr key.
May 7 '09 #7
FishVal
2,653 Expert 2GB
@OldBirdman
I'm afraid I don't follow. What has been simplified by this table?

Kind regards,
Fish.
May 7 '09 #8
OldBirdman
675 512MB
Spanning Midnight. Aren't your dteStart and dteEnd actually times. Then dteStart = "23:00" is greater than dteEnd = "06:59:59"
May 7 '09 #9
FishVal
2,653 Expert 2GB
@OldBirdman
It do affect nothing. :)
May 7 '09 #10
OldBirdman
675 512MB
OK. I read that link about Grouping Query Range, and didn't really follow. But I don't have the problem myself, so I didn't generate a test database. So I mis-understand. So forget my idea. in post #7. Thank you FishVal for watching out for NSkram79 and not allowing me to muck things up.
May 7 '09 #11
NeoPa
32,556 Expert Mod 16PB
I see where you're going OB, but I think Fish's solution is probably more flexible and robust. Your point about midnight is a good one though, and the table may well need an AutoNumber PK as well as a field to identify the shift number. Two separate records would be required for the shift spanning midnight. Different PK values, but the same [ShiftNo] value.

Linking would be along the lines of :
Expand|Select|Wrap|Line Numbers
  1. SELECT Security.XXX,
  2.        Shift.ShiftNo,
  3.        ...
  4.  
  5. FROM   [Security] INNER JOIN [Shift]
  6.   ON   Security.EntryTime Between Shift.Start And Shift.End
May 12 '09 #12
OldBirdman
675 512MB
Probably off-topic, but this is really a very common issue. Program needs a number for a small list of words. We build these little tables for Months of the Year so May->5, Choices like "Yes", "No", "Maybe", "Not Applicable" so Maybe->3, etc. These lists also exist as Value Lists for combo boxes. Either requires a programmer to change, but admittedly it is easier to change tables or controls than find the VBA statements that have tricky algorithms to do it.

Is there an easy way to use an .INI file for this? That would make changing the month names to another language very easy. For this thread, .INI file might be:
Expand|Select|Wrap|Line Numbers
  1. FirstShiftStart=07:00
  2. SecondShiftStart=15:00
  3. ThirdShiftStart=23:00
  4.  
I would then call a function that returned the value of 1, 2, or 3.
Expand|Select|Wrap|Line Numbers
  1.     intShiftNumber = ShiftValue([EntryTime], _
  2.             FirstShiftStart, SecondShiftStart, ThirdShiftStart)
May 12 '09 #13
NeoPa
32,556 Expert Mod 16PB
I have to admit, if I'm already in a database system, I'll use the tables every time. They can be incorporated into functions if desired, but they fit the requirement so fundamentally well.

The multi-language example, for instance, is so easy to implement. Just add an extra field to identify the language. The data's still all held in the table, and the performance won't degrade.

Everyone has their opinions of course, and that's how it should be, but this is mine.
May 12 '09 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Zhang Le | last post by:
Hi, I did a small benchmark of matrix-vector multiply operation using Numeric module. I'm a bit suprised to find matrix*col-vector is much faster than row-vector*matrix. I wonder whether other...
1
by: Luigi Ida' via SQLMonster.com | last post by:
Hi, I have a php application connected through odbc to a sqlserver database. When I try to execute select queries on a smalldatetime table field I receive this message: Warning: Numeric value...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
9
by: ckerns | last post by:
I want to loop thru an array of controls,(39 of them...defaults = 0). If value is null or non-numeric I want to assign the value of "0". rowString = "L411" //conrol name if (isNaN(eval...
2
by: MrNobody | last post by:
I just noticed that a numeric up/down will let you manually type in any number even if it is beyond the min/max range you specified. The control will not actually return this value if it is...
7
by: Sheldon | last post by:
Hi, I have the following loop that I think can be written to run faster in Numeric. I am currently using Numeric. range_va = main.xsize= 600 main.ysize= 600 #msgva is an (600x600) Numeric...
2
by: tron_23 | last post by:
hi, we use Toplink (TopLink - 4.6.0 (Build 417) with a DB2 Database 7.2. i know really old versions, but we could change to e newer one ;-) Sometimes we got some problems with update or insert...
1
by: Navs | last post by:
Hi, I am trying to insert a TIME value in a SQL Server 2008 database using a simple ODBC C program. I follow the steps below: 1. Connect and Allocate Statement handle 2. Prepare a Statement...
0
by: hydro123 | last post by:
I am using VC++2008 and am trying to read data enetered in unbound datagridview to implement in function. Under button_click event I entered the following: // initialize varaibles from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.