Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting "short time" to minutes

Status
Not open for further replies.

optiplex

Technical User
Jul 21, 2000
2
SE
I have used this routine to extract the mins and hours from
starttime and endtime:
timeused=Format([StartTime]-1-[EndTime],"Short Time") and
the result is for example 03:15.
How to convert this result into minutes ?

/opti
 
The first thing that comes to mind is something like this...

iMinutes = format(<your time result>, &quot;hh&quot;) * 60 ' Returns the minutes

You can then add iMinutes to the remaining minutes for the final result.

Gary
gwinn7
 
If you have a string &quot;timeused&quot; containing hours and minutes in the format &quot;hh:mm&quot;, you can convert it to minutes with the following expression:
Val(Left$(timeused,2)) * 60 + Val(Mid$(timeused,4,2))

I don't understand your calculation (StartTime-1-EndTime) of timeused, however. Shouldn't it be EndTime-StartTime?

Anyway, while the string method will work, it's actually much simpler to just convert the time value directly into minutes with:
(EndTime - StartTime) * 1440.0
That will give you a floating point result in minutes and fractional minute, which you can round if you wish. Rick Sprague
 
Lots of ways!
If you are just interested in minutes, I'd do this:

timeused=Int(([EndTime]-[StartTime])*24*60)
or rather
timeused=Int(([EndTime]-[StartTime])*1440)
Jeffrey Bell
jbell@westlakegrp.com
 
StartTime = #8:00 AM#
EndTime = Format(Now, &quot;Short Time&quot;)
TimeUsed = DateDiff(&quot;n&quot;, StartTime, EndTime)
? StartTime, EndTime, TimeUsed
8:00:00 AM 09:40 100


to use with fields, add the square brackets. al-la below
TimeUsed = DateDiff(&quot;n&quot;, [StartTime], [EndTime])

MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
You could also use the DateDiff function DATEDIFF(&quot;S&quot;, [StartTime], [EndTime])/60 This will break it all the way down by the second (still show it in hours and minutes)

Change the &quot;s&quot; to &quot;m&quot; for minutes /1440

(Not sure about dividing by 1440, been a while since I've used it)
 
CaptainD,

Typo? &quot;m&quot; is NOT &quot;M&quot;inutes.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top