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).
25 3594
It is relatively easy to round the total time, if that is what you are after: - Public Function RoundTime( _
-
ByVal datDate As Date) _
-
As Date
-
-
Const cintMult As Integer = 48 '30 minute round
-
'Const cintMult As Integer = 96 '15 minute round
-
'Const cintMult As Integer = 144 '10 minute round
-
'Const cintMult As Integer = 288 '5 minute round
-
-
RoundTime = CDate(Int(datDate * cintMult + 0.5) / cintMult)
-
-
End Function
-
-
Public Function RoundTimeUp( _
-
ByVal datDate As Date) _
-
As Date
-
-
Const cintMult As Integer = 48 '30 minute round
-
'Const cintMult As Integer = 96 '15 minute round
-
'Const cintMult As Integer = 144 '10 minute round
-
'Const cintMult As Integer = 288 '5 minute round
-
-
RoundTimeUp = CDate(-Int(-datDate * cintMult) / cintMult)
-
-
End Function
Nevermind. I don't know how to word this to make sense. Sorry to have wasted anyone's time.
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.
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.
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).
ADezii 8,834
Recognized Expert Expert
Give me a little time, and I'll see what I can come up with.
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: - Public Function FormatHourMinuteSecond( _
-
ByVal datTime As Date, _
-
Optional ByVal strSeparator As String = ":") _
-
As String
-
-
' Returns count of days, hours, minutes, and seconds of datTime
-
' converted to hours, minutes, and seconds as a formatted string
-
' with an optional choice of time separator.
-
'
-
' Example:
-
' datTime: #10:03:55# + #20:01:24#
-
' returns: 30:05:19
-
'
-
' 2014-06-17. Cactus Data ApS, CPH.
-
-
Dim strHour As String
-
Dim strMinuteSec As String
-
Dim strHours As String
-
-
strHour = CStr(Fix(datTime) * 24 + Hour(datTime))
-
' Add leading zero to minute and second count when needed.
-
strMinuteSec = Right("0" & CStr(Minute(datTime)), 2) & strSeparator & Right("0" & CStr(Second(datTime)), 2)
-
strHours = strHour & strSeparator & strMinuteSec
-
-
FormatHourMinuteSecond = strHours
-
-
End Function
For an optimised and speedy entry of durations, please study my project VBA.TimeEntry Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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
|
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
|
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?
|
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
| |
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 ?
|
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...
|
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
{
|
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))
...
|
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
........
........
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |