By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,398 Members | 1,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,398 IT Pros & Developers. It's quick & easy.

Duration of time

P: 1
I am trying to create a field that I can list the time that a flight lasted in minutes and seconds. This is not a time of day but just a duration such as 25 minutes and 35 seconds. This would be similar to a cd collection where you have how long a song is then be able to sum the total of any given songs.
Aug 3 '07 #1
Share this Question
Share on Google+
1 Reply


missinglinq
Expert 2.5K+
P: 3,532
Here's a start. It takes a Start time and a Finish time and gives the answer in the format of 02:30:45 for 2 hours 30 minutes and 45 seconds. I assume we're talking about RC planes, since you speak of flight durations in terms of minutes/seconds, but I included the hours for doing totals of the flight time then displaying the results.

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. Duration = HoursLapsed & ":" & MinutesLapsed & ":" & SecondsLapsed
  19.  
  20. End Sub
  21.  
As a strategy towards totalling flight times, I'd store the variable TotalSeconds in a field for each flight, then take Sum of TotalSeconds and run it thru the same formula as above!

Welcome to TheScripts!

Linq ;0)>
Aug 3 '07 #2

Post your reply

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