473,666 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Round a Duration

ahayesfx
6 New Member
I'm having an issue related to this old thread (how best to format time duration?). I made the same mistake as the original user, which I've corrected, but I'm stuck on the calculated portion of the solution. I want to know how to calculate for total time in specific increments, i.e. 30-minutes, 1-hour, etc. I've tried everything, but can't seem to make it happen.

{Admin Edit}
This post has been moved from the original thread (linked above) as posting your own questions in existing threads is hijacking - which is not allowed here (or in most forums).
Oct 11 '19 #1
25 3594
cactusdata
214 Recognized Expert New Member
It is relatively easy to round the total time, if that is what you are after:

Expand|Select|Wrap|Line Numbers
  1. Public Function RoundTime( _
  2.     ByVal datDate As Date) _
  3.     As Date
  4.  
  5.     Const cintMult As Integer = 48 '30 minute round
  6.     'Const cintMult As Integer = 96 '15 minute round
  7.     'Const cintMult As Integer = 144 '10 minute round
  8.     'Const cintMult As Integer = 288 '5 minute round
  9.  
  10.     RoundTime = CDate(Int(datDate * cintMult + 0.5) / cintMult)
  11.  
  12. End Function
  13.  
  14. Public Function RoundTimeUp( _
  15.     ByVal datDate As Date) _
  16.     As Date
  17.  
  18.     Const cintMult As Integer = 48 '30 minute round
  19.     'Const cintMult As Integer = 96 '15 minute round
  20.     'Const cintMult As Integer = 144 '10 minute round
  21.     'Const cintMult As Integer = 288 '5 minute round
  22.  
  23.     RoundTimeUp = CDate(-Int(-datDate * cintMult) / cintMult)
  24.  
  25. End Function
Oct 12 '19 #2
ahayesfx
6 New Member
Nevermind. I don't know how to word this to make sense. Sorry to have wasted anyone's time.
Oct 12 '19 #3
NeoPa
32,568 Recognized Expert Moderator MVP
Hi ahayesfx.

First welcome to Bytes.com.

I had to move these posts as posting new questions in an existing thread (called hijacking) is not allowed here (or on most forum sites actually).

You come across as considerate and at least a little bright. Few would recognise how adequate a question is when it's their own question. Shame but true. Have you considered posting some sample data showing the data you start with as well as the results you hope to attain? Some people post sample data only and wonder why no-one understands what they want but if posted with a question that gets most of the idea across it can be invaluable. It's up to you of course but it could be that we're all but there for the want of a little push.

I'll leave it with you.
Oct 13 '19 #4
ahayesfx
6 New Member
I didn't mean to hijack the previous thread. I simply found a thread and solution that was similar to my question and made an amendment. It won't happen again.

Here's what I'm up against: I have a list of songs, varying in length, hundreds of them, and I want to build a series of queries that anytime one of them is ran, it will randomly select 15-minutes worth of songs, 30-minutes, 1-hour, 2-hour, 6-hour, etc. I have the randomizer already in-place, but I can't seem to configure the total times for each query. Instead of the Date/Time format, I used Short Text with an input mask of 00:00:00. My reason for doing this is because Access wants to automatically convert times into AM/PM, and I need it to track duration. In the query, I’ve set up three expressions: one for hours, one for minutes, and one for seconds. I thought doing so would help me in returning the totals. Unfortunately, this is where I get stuck.

EDIT: It's like when you want to return 'Top Values' in a query, except I want to return it by the total times listed above.

I hope all this makes sense. It doesn't seem like this should be as difficult as I'm making it, but yet here I am. Thank you for your assistance.
Oct 13 '19 #5
ADezii
8,834 Recognized Expert Expert
Unless I am reading this incorrectly, you wish to select a Random Number of Songs, but keep the Total Duration of these Songs under some predetermined Value represented by Y? Should this premise be true, display some simple Data showing how each Song Title and Duration are stored. All other information (Artist, Label, etc.) is irrelevant for this discussion (IMHO).
Oct 13 '19 #6
ahayesfx
6 New Member
I think what you said in your response is what I'm looking to do. I hope these screenshots help.

https://drive.google.com/open?id=1-E...Jmx5GL2dbSqQPA

https://drive.google.com/open?id=1qq...zpQTpAN3ABaH-M

https://drive.google.com/open?id=10K...TID8l_mSE-sFM4

https://drive.google.com/open?id=1Wv...N-5Bof7THpdnOt

I just want to build a series of queries with a predetermined total: 15-minutes, 30-minutes, 1-hour, 2-hour, 6-hour, etc. For context purposes, I own and operate a radio station. I'm seeking to simplify the rotation and live show building processes. To accomplish this with an extremely limited staff, I built my own application. Thank you for all your help.
Oct 13 '19 #7
ADezii
8,834 Recognized Expert Expert
Give me a little time, and I'll see what I can come up with.
Oct 13 '19 #8
ahayesfx
6 New Member
I greatly appreciate it.
Oct 13 '19 #9
cactusdata
214 Recognized Expert New Member
Instead of the Date/Time format, I used Short Text with an input mask of 00:00:00. My reason for doing this is because Access wants to automatically convert times into AM/PM, and I need it to track duration.

This is definitely a dead end. Time(span) should always be handled using DateTime, not text, not numbers, no exceptions.

So, just sum the durations and format the result as you prefer. For spans exceeding 24 hours, however, a custom function like this must be used for display:

Expand|Select|Wrap|Line Numbers
  1. Public Function FormatHourMinuteSecond( _
  2.   ByVal datTime As Date, _
  3.   Optional ByVal strSeparator As String = ":") _
  4.   As String
  5.  
  6. ' Returns count of days, hours, minutes, and seconds of datTime
  7. ' converted to hours, minutes, and seconds as a formatted string
  8. ' with an optional choice of time separator.
  9. '
  10. ' Example:
  11. '   datTime: #10:03:55# + #20:01:24#
  12. '   returns: 30:05:19
  13. '
  14. ' 2014-06-17. Cactus Data ApS, CPH.
  15.  
  16.   Dim strHour       As String
  17.   Dim strMinuteSec  As String
  18.   Dim strHours      As String
  19.  
  20.   strHour = CStr(Fix(datTime) * 24 + Hour(datTime))
  21.   ' Add leading zero to minute and second count when needed.
  22.   strMinuteSec = Right("0" & CStr(Minute(datTime)), 2) & strSeparator & Right("0" & CStr(Second(datTime)), 2)
  23.   strHours = strHour & strSeparator & strMinuteSec
  24.  
  25.   FormatHourMinuteSecond = strHours
  26.  
  27. End Function
For an optimised and speedy entry of durations, please study my project VBA.TimeEntry
Oct 13 '19 #10

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

Similar topics

1
2237
by: Dave | last post by:
Greetings, I am trying to create a duration field in a query. I have a field with a start time and a field with an end time. They are both in military time, and are formatted as hours:minutes. I am trying to create a duration field by subtracting the start time from the end time. This is working. However, some end times do not happen until the following day, and this is screwing up the results. If the start time is 04:30 and the
4
5702
by: Stephen Young | last post by:
Hello Have a bit of a problem, im trying to get the total number of hours:minutes for all actions over the month in a query, have tried two methods to no luck... Duration This Month: Format(Sum(.-.),"hh:nn") displays the total hours but rolls over anything over 1 day and starts
15
2042
by: bcpkh | last post by:
Hello All I have a simple task that is driving me crazy. A string representing a duration in the following format is passed to my application, a function is dedicated to convert this duration to seconds; H:MM:SS e.g. 0:00:00 or 00:12:45
3
2317
by: Keith Wilby | last post by:
Here's something I thought I'd know how to do ... I have an Appointments table and want to add a duration (integer representing hours) to a start time (Date/Time field, "Short Time" format) to give a finish time. I want to do this in a query but if I do + I get a date returned. I've tried using the Format function to no avail. What forehead slappingly obvious trick am I missing?
15
42613
karthickkuchanur
by: karthickkuchanur | last post by:
Hai sir, i assigned to calculate the age from current date ,i have the date of birth of employee from that i have to calculate the age dynamically, i refer to google it was confusing me .please give some idea to do sir
1
3755
by: Giacomo Catenazzi | last post by:
Hello, To learn the details of C, I've build the following example, could you check if it is correct and if it miss some important cases? Are there some useful (real cases) examples of: - "function prototype scope" for structures and unions? - "extern" for internal linkage ?
1
2819
by: to1234 | last post by:
create table #ExamDur(DtTm datetime,startTm datetime,EndTm datetime,Duration int,duration1 varchar(20)) insert into #ExamDur(DtTm,startTm,EndTm,Duration,duration1) select UE.CreatedDtTm,ED.StartTime,ED.EndTime, datediff(mi,ed.starttime,ed.endtime) duration , cast(datediff(mi,ED.StartTime,ED.EndTime)as varchar(20))+':'+ cast(DATEPART(SECOND,(ed.EndTime-ed.StartTime) )as varchar(20)) Duration1 from UserExamMap UE left join ExamDuration ED...
0
1958
by: mrcw | last post by:
Hi, I'm trying to sound a beep, the freq and duration I send to the method that make's the sound, e.g makebeep(10000, 100). The obvious way seems to be from a button to a method. Here's what I've tryed so far. using System; using System.Collections.Generic; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Media; namespace Beep {
2
5166
by: Sudarshan1 | last post by:
I am on a elementary level of MS Access skill. I am trying to create an expression, where I want to round up the value in a field. Expr1: ROUNDUP(Data!/60,0) When executing the qry, I get : "Undefined function "ROUNDUP" in expression, I am using Access 2000. What am I doing wrong, or Is there another way ? After that we have use below formula but it not completely correct IF((Data!/60)-INT(Data!/60)<0,(ROUND(Data!/60,0)+1),(Data!/60)) ...
29
3238
by: rajeevs | last post by:
I have an access table (MasterLogs)with Date, UserName, Position, loginTime, logoutTime.(Login and logout field type is date&time). I am trying to read each record in this table and add records to another table (PositionHrs). The field in that table are: Date Username Position 0000-0059 0100-0159 0200-0259 ........ ........
0
8356
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,...
0
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8640
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...
1
6198
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
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
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
2011
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.