473,396 Members | 1,804 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,396 software developers and data experts.

Time difference based on multiple records

171 100+
Hi

I am looking for a formula or code which can perform a calculation as per the attched file.
The records can be in ACCESS table with an ID.
Please help
Attached Files
File Type: xlsx time calculation.xlsx (9.1 KB, 372 views)
Jun 23 '14 #1

✓ answered by NeoPa

Assuming your DateTime values are in Column A and you want the updated values in Column B such that Column B is always at least 5 minutes after Column B of the previous record then place the following formula in Comlumn B (Cell("B2") and drag down :
Expand|Select|Wrap|Line Numbers
  1. =IF($B1+5/1440>$A2,$B1+5/1440,$A2)
Make sure the column is formatted for date values if you want to see it that way. It won't be automatic as is usually the case when entering date values.

19 1333
jimatqsi
1,271 Expert 1GB
rajeevs,
I'm afraid your "question" doesn't make any sense. There's nothing to answer. What do you want? What calculation? Please take the time to spell out clearly what you want. And remember that most people are not going to download your attachment.

Jim
Jun 23 '14 #2
twinnyfo
3,653 Expert Mod 2GB
rajeevs,

Exactly what is your table trying to do? Your table (in the expected column) does not seem to make any sense as to what you want it to calculate.

Any time you calculate dates and times can be tricky in Excel or Access. Your spreadsheet "seems" straightforward, but without knowing exactly what you want to do, it is difficult to proerly advise.
Jun 23 '14 #3
rajeevs
171 100+
Thank you jim & twinnyfo
I have a recordset with an entry time field. the records will be in a sort order based on the entry time. I want to find out if any record has an entry time less than 5 minutes compared to the previous record then I need to change the entry time of that record to have a separation of five minutes with the previous record and next record. Hope I have explained the issue correctly. Please help me
Jun 23 '14 #4
jimatqsi
1,271 Expert 1GB
Look at the datediff() function. It will return the difference between two dates or times. You can ask for the difference in months, days, years, minutes, seconds, etc ...
Jun 23 '14 #5
twinnyfo
3,653 Expert Mod 2GB
rajeevs,

if you have your recordset, sorted by entry time, then simply cycle through those records. You should then compare the times, using the DateDiff() Function.

Expand|Select|Wrap|Line Numbers
  1. Private Sub ResetTimeField()
  2.     'This is assuming you already have your recordset
  3.     Dim intRcds As Integer
  4.     Dim intCounter As Integer
  5.     Dim dtPrevious As Date
  6.     With rst
  7.         .MoveLast
  8.         intRcds = .RecordCount
  9.         .MoveFirst
  10.         dtPrevious = !DateEntryField
  11.         .MoveNext
  12.     End With
  13.     For intCounter = 1 To intRcds - 1
  14.         If DateDiff("n", rst!DateEntryField, dtPrevious) < 5 Then
  15.             With rst
  16.                 !DateEntryField = dtPrevious + (1 / 24 / 60 * 5)
  17.                 dtPrevious = !DateEntryField
  18.             End With
  19.         Else
  20.             dtPrevious = rst!DateEntryField
  21.         End If
  22.         rst.MoveNext
  23.     Next intCounter
  24. End Sub

This code may seem a bit strange, because using the DateDiff() function doesn't work to well when wadding values to dates/times.

In line 16, you have the expression "(1 / 24 / 60 * 5)". This is calculating the decimal expressed by five minutes of time (dates are whole numbers, times are a decimal part of that number).

Hope this helps!
Jun 23 '14 #6
NeoPa
32,556 Expert Mod 16PB
Assuming your DateTime values are in Column A and you want the updated values in Column B such that Column B is always at least 5 minutes after Column B of the previous record then place the following formula in Comlumn B (Cell("B2") and drag down :
Expand|Select|Wrap|Line Numbers
  1. =IF($B1+5/1440>$A2,$B1+5/1440,$A2)
Make sure the column is formatted for date values if you want to see it that way. It won't be automatic as is usually the case when entering date values.
Jun 23 '14 #7
rajeevs
171 100+
Thank you twinnyfo & NeoPa

First I tried NeoPa's solution in Excel and it worked perfect. Thank you so much.
I wanted to try twinnyfo's code with ACCESS tbl but when I run the code it is showing error 3020.
I define the tbl as SeparationTbl and tried to run the code.
runtime error 3020
"Update or CancelUpdate without Addnew or Edit"
I have the time in ExitTime Field and I want to update another blank field named as NewExitTime with the 5 minutes separation new timing
Hope you will help me to finetune the code and achieve the result. Thank you both of you for the quick solutions
Jun 24 '14 #8
twinnyfo
3,653 Expert Mod 2GB
I forgot to include the edit and update commands.

Starting at line 17:

Expand|Select|Wrap|Line Numbers
  1.             .Edit
  2.             dtPrevious = !DateEntryField
  3.             .Update
My mistake. Let me know if this corrects your errors.
Jun 24 '14 #9
rajeevs
171 100+
@twinnyfo
Thank you for the time and consideration
I will try agian and let you know
Jun 24 '14 #10
rajeevs
171 100+
Thank you twinnyfo

After running the code it is sequencing the time. That is not the result I am looking for. It need to check 1 record above and one record below and then allocate 5 minutes between the records from their time (same as the attached Image)

Attached Images
File Type: jpg Rajeevs.Jpg (27.1 KB, 152 views)
Jun 26 '14 #11
twinnyfo
3,653 Expert Mod 2GB
Your attachment is unreadable. You are trying to change the current recordset, correct? Please explain.
Jun 26 '14 #12
rajeevs
171 100+
Sorry for the delay. I was on holidy for two days.
I have attached a small excel worksheet to give you an idea about what is my requestsample.xlsx
Jun 29 '14 #13
NeoPa
32,556 Expert Mod 16PB
Not sure that works too well either Rajeev, but possible if you download then rename the extension.

I took a snap and attached it to your earlier message though and that now shows more legibly.

PS. As you already have a working answer - why is it that you want a specifically code-based solution? Typically I find that formulas in the cells are preferable, but you seem to want it the other way around. Not a problem, of course, but I'm just curious.
Jun 29 '14 #14
rajeevs
171 100+
I am trying to implement it in an ACCESS DB. Then it will be much easier for future use. Otherwise every time I have to transfer the data to Excel and do it in Excel. Hope I am not asking too much. Thank you NeoPa. twinnyfo's code can do the desired rsult if it is fine tuned which I am unable to do myself. That is why I am bothering you all. Thank you for the understanding
Jun 29 '14 #15
NeoPa
32,556 Expert Mod 16PB
Not at all. That's perfectly acceptable :-)

What you will need to decide though, because tables contain sets of data rather than a single ordered list, is which order you are referring to when you specify anything that is next or previous. In set terms those words are meaningless. A little like trying to quote area in meters. It's not possible because area is measured in square meters.
Jun 29 '14 #16
rajeevs
171 100+
@NeoPa
Dear NeoPa
Thank you for the reply. The data will be ordered on the time field and records will be having IDs as well.
So it will be easy to refer to previous record either by ID or the order of time field
Jun 30 '14 #17
NeoPa
32,556 Expert Mod 16PB
Are you thinking of updating the data in place or simply showing the amended data when querying the table?
Jun 30 '14 #18
rajeevs
171 100+
@NeoPa
If coding is difficult a query with additionl field with the amended time will also help me
Jul 1 '14 #19
NeoPa
32,556 Expert Mod 16PB
What are you actually after. I'm trying to avoid doing it twice. Both are possible.
Jul 3 '14 #20

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

Similar topics

12
by: shank | last post by:
I'm trying to use online samples for submitting multiple records from ASP into a stored procedure. Failing! Through the below form, a user could be submitting many records at a time. I'm not...
4
by: iamonthisboat | last post by:
I have a data set like so: UTC_TIME Timestamp NodeID Message Flag Line Station 11/19/2005 10:45:07 1132397107.91 1 3 5 1028 1034...
5
by: Kaur | last post by:
Hi, I have been successful copying a vba code from one of your posts on how to copy and paste a record by declaring the desired fields that needs to be copied in form's declaration and creating two...
3
by: chalrav | last post by:
Reading through multiple records, with Loop capability -------------------------------------------------------------------------------- Hi, I have three tables as below: Table: Demand...
4
4Him
by: 4Him | last post by:
First off, let me say this is a great site! I've just started working with Access and much of my success is from what I've read here! Background: I have a form, driven off a single table. Goal:...
1
by: visitram | last post by:
I am a newbie to Ruby and wondering how to insert multiple records at the same time. I want to create a form such that it accept multiple records and save it to DB upon submitting the form...
5
by: jrodcody | last post by:
Hello: I am trying to create multiple records in a table named tblTravel based on the input of a date range in two form controls. The inputs for the form are LastName, TravelDate, EndDate,...
3
by: ganesh22 | last post by:
Hi, xmlw = new XmlTextWriter("c:\\testing.xml",null); xmlw.WriteStartDocument(); xmlw.WriteStartElement("Company"); xmlw.WriteStartElement("Software");...
8
by: cehlinger | last post by:
I am trying to add multiple records based on a date range. I found some examples and have tried them but am getting errors and I can't seem to figure out what the problem is. I am not a VBA...
3
by: Gareth Jones | last post by:
Hi all, I have a database that records issues and incidents based on different priorities. I am trying to write a query to show the time difference since the last incident depending on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.