473,792 Members | 2,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Time/ Date How much time has elapsed

1 New Member
I am new to access and have created a database. I have created a couple of fields
Date/ Time of Call
Date and Time of placement
Date and time of procedure

I need to calculate the differance between Date and time of initial call
Differance between Date / Time of placement
Differance between Date/ Time of procedure.

Times are in 2:30:00 PM and 14: 30 formats.

Can I perform these calculations and how do I go about doing this. I am at loss.
Thank you
J
Feb 10 '07 #1
9 3034
ADezii
8,834 Recognized Expert Expert
I am new to access and have created a database. I have created a couple of fields
Date/ Time of Call
Date and Time of placement
Date and time of procedure

I need to calculate the differance between Date and time of initial call
Differance between Date / Time of placement
Differance between Date/ Time of procedure.

Times are in 2:30:00 PM and 14: 30 formats.

Can I perform these calculations and how do I go about doing this. I am at loss.
Thank you
J
For what Interval do you wish to calculate the differences? For detailed information on calculating the differences between Dates and Times, please reference the DateDiff() Function. If you encounter any problems, please let us know.
Feb 10 '07 #2
NeoPa
32,579 Recognized Expert Moderator MVP
A simple subtraction will give you the result you're after.
Unfortunately, the result will be a simple floating point result showing number (including fraction) of days. This can be formatted to show (separately) the number of days ("0") and Hours minutes and seconds ("HH:nn:ss" or "h ""hours, ""n ""minutes and ""s""seconds."" ").
Feb 11 '07 #3
nico5038
3,080 Recognized Expert Specialist
Checkout the datetime differences and other items at:
http://www.mvps.org/access/datetime/index.html

Fine site with much info !

Nic;o)
Feb 11 '07 #4
cedonahue3
1 New Member
need to calculate hours worked. Example, 17:30 to 3:30 should be 10 hours worked.

thank,
chris
Aug 18 '07 #5
ADezii
8,834 Recognized Expert Expert
need to calculate hours worked. Example, 17:30 to 3:30 should be 10 hours worked.

thank,
chris
Expand|Select|Wrap|Line Numbers
  1. Dim dteBeginTime As Date, dteEndTime As Date, intHoursDiff
  2.  
  3. dteBeginTime = #5:30:00 PM#
  4. dteEndTime = #3:30:00 AM#
  5.  
  6. intHoursDiff = DateDiff("h", dteBeginTime, dteEndTime)
  7.  
  8. If intHoursDiff < 0 Then
  9.   Debug.Print "Elapsed Hours: " & 24 - Abs(intHoursDiff)
  10. Else
  11.   Debug.Print "Elapsed Hours: " & intHoursDiff
  12. End If
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Elapsed Hours: 10
Aug 18 '07 #6
missinglinq
3,532 Recognized Expert Specialist
With the controls named Start, Finish and TotalTime holding the obvious data, this will do it down to the second! If you want to drop the seconds, omit Lines 13-16 and change Line 18 to read

TotalTime = HoursLapsed & ":" & MinutesLapsed

Expand|Select|Wrap|Line Numbers
  1. Private Sub Finish_BeforeUpdate(Cancel As Integer)
  2.  TotalSeconds = DateDiff("s", start, finish)
  3.  
  4.  HoursLapsed = Int(TotalSeconds / 3600)
  5.  If HoursLapsed = 0 Then HoursLapsed = "00"
  6.  
  7.  SecondsLeft = TotalSeconds Mod 3600
  8.  
  9.  MinutesLapsed = Int(SecondsLeft / 60)
  10.  If MinutesLapsed = 0 Then MinutesLapsed = "00"
  11.  If MinutesLapsed <> 0 And Len(MinutesLapsed) = 1 Then MinutesLapsed = "0" & MinutesLapsed
  12.  
  13.  SecondsLapsed = SecondsLeft Mod 60
  14.  
  15.  If SecondsLapsed = 0 Then SecondsLapsed = "00"
  16.  If SecondsLapsed <> 0 And Len(SecondsLapsed) = 1 Then SecondsLapsed = "0" & SecondsLapsed
  17.  
  18.  TotalTime = HoursLapsed & ":" & MinutesLapsed & ":" & SecondsLapsed
  19.  
  20.  End Sub
Welcome to TheScripts, Jackson1 and cedonahue3!

Linq ;0)>
Aug 18 '07 #7
ADezii
8,834 Recognized Expert Expert
With the controls named Start, Finish and TotalTime holding the obvious data, this will do it down to the second! If you want to drop the seconds, omit Lines 13-16 and change Line 18 to read

TotalTime = HoursLapsed & ":" & MinutesLapsed

Expand|Select|Wrap|Line Numbers
  1. Private Sub Finish_BeforeUpdate(Cancel As Integer)
  2.  TotalSeconds = DateDiff("s", start, finish)
  3.  
  4.  HoursLapsed = Int(TotalSeconds / 3600)
  5.  If HoursLapsed = 0 Then HoursLapsed = "00"
  6.  
  7.  SecondsLeft = TotalSeconds Mod 3600
  8.  
  9.  MinutesLapsed = Int(SecondsLeft / 60)
  10.  If MinutesLapsed = 0 Then MinutesLapsed = "00"
  11.  If MinutesLapsed <> 0 And Len(MinutesLapsed) = 1 Then MinutesLapsed = "0" & MinutesLapsed
  12.  
  13.  SecondsLapsed = SecondsLeft Mod 60
  14.  
  15.  If SecondsLapsed = 0 Then SecondsLapsed = "00"
  16.  If SecondsLapsed <> 0 And Len(SecondsLapsed) = 1 Then SecondsLapsed = "0" & SecondsLapsed
  17.  
  18.  TotalTime = HoursLapsed & ":" & MinutesLapsed & ":" & SecondsLapsed
  19.  
  20.  End Sub
Welcome to TheScripts, Jackson1 and cedonahue3!

Linq ;0)>
Nice approach, ling. Just a suggestion, you may want to allow for the post Midnight barrier: a Start Time of 17:30 and a Finish Time of 03:30 will yield -14 instead of 10.
Aug 18 '07 #8
ADezii
8,834 Recognized Expert Expert
need to calculate hours worked. Example, 17:30 to 3:30 should be 10 hours worked.

thank,
chris
One point to note:
However you arrive at the final calculations, you should always make sure you have valid entries in the Start and Finish Times as in:

Expand|Select|Wrap|Line Numbers
  1. If Not IsDate(Me![Start]) Or Not IsDate(Me![Finish]) Then Exit Sub
Aug 18 '07 #9
missinglinq
3,532 Recognized Expert Specialist
Yeah, I know! The full version does! It was actually designed to use a TimeIn and TimeOut button that used Now() which assures real dates/times, but the supervisors needed to go in and change some times, and I knew they'd mess it up! If the code's to be used in a situation where time only is input manually, then you would have to add code to check that valid times have been entered and to handle situations where midnight occurs between Start and Finish.

Linq ;0)>
Aug 18 '07 #10

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

Similar topics

1
1376
by: Sara Khalatbari | last post by:
Is there a Modules in Python that returns the time & date of today when ran?
18
10309
by: Robin Lawrie | last post by:
Hi again, another problem! I've moved from an Access database to SQL server and am now having trouble inserting dates and times into seperate fields. I'm using ASP and the code below to get the date and time, but my script is erroring. '-- Get login date and time cmdLoginDate = Date() cmdLoginTime = Time()
8
3409
by: peterbe | last post by:
What's the difference between time.clock() and time.time() (and please don't say clock() is the CPU clock and time() is the actual time because that doesn't help me at all :) I'm trying to benchmark some function calls for Zope project and when I use t0=time.clock(); foo(); print time.clock()-t0 I get much smaller values than when I use time.clock() (most of them 0.0 but some 0.01) When I use time.time() I get values like...
9
3229
by: Bob Achgill | last post by:
I would like to use the timestamp on files to manage the currency of support files for my VB windows application. In this case I would only put the timestamp of the file in the management database and not the file itself. To do this I will need to have a File class property for Create time and date that will let me "set" the Create time and date of the file to my own chooseing. The VB file class does not appear to have the ability
13
16175
by: maflatoun | last post by:
Hi, I have the following function to convert UTC time to Local time. It works perfect for GMT- (Minus) time zones however it provides incorrect results for GMT+(Plus) time zones? // Format to local time from UTC function formatToLocalTimeDate(inDate) { var today = new Date(); var inDateMod = new Date(inDate);
15
2342
by: Cerebral Believer | last post by:
Hi all, I am a newbie to JavaScript and am just trying to get a script going that will write the ful date and time to each webpage as it is viewed. Can anyone point out what mistakes there are in my code, as it does not seem to work? I am actually trying to learn what parts of the code do what and why, so if anyone can take the time to explain it would be much appreciated. Here is my script: <script language="javascript">
2
22659
by: drurjen | last post by:
Good morning. I am importing an XLS file into one of my tables. The fields are: Date Id Time IO 12/22/2006 2 12:48:45 PM 9 12/22/2006 16 5:40:55 AM 1 12/22/2006 16 12:03:59 PM 2 When I do the import, I get the following:
2
1318
by: silverburgh.meryl | last post by:
Hi, I have the following code which spawn a number of thread and do something (in the run method of MyThread). how can I record how much time does EACH thread takes to complete the 'run'? for j in range(threadCount): t = MyThread(testNo) threads.append(t)
2
3739
by: Yew12 | last post by:
We are trying to get the following script to display the full date and time. The field we are calling does have both date and time in. Unfortunatly its only returning the date. So I tried putting the sql "to_date('Adate','dd/mm/yyyy hh24:mi')" to disply the full field. No Luck Any help is much appresiated. Thanks.<HTML> <HEAD><TITLE> Property Results </TITLE> </HEAD> <BODY> <?php $sql="Select * from Appointment where Appointment_id =...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10159
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9033
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.