Format Time field in only Minutes and Seconds

G

Guest

In a previous post (which I can't find) I had asked a question about time
being displayed in only minutes and seconds. There was a response about
using the Format command, however I am having problems getting that to work

Mytime = Format(Hour([StartTime])*60 + Minute([StartTime]),"00:") &
Format(Second([StartTime]),"00")

what am I doing wrong with this?
 
M

Marshall Barton

Ron said:
In a previous post (which I can't find) I had asked a question about time
being displayed in only minutes and seconds. There was a response about
using the Format command, however I am having problems getting that to work

Mytime = Format(Hour([StartTime])*60 + Minute([StartTime]),"00:") &
Format(Second([StartTime]),"00")

what am I doing wrong with this?


Doesn't look like anything's wrong. What value does
StartTime have? What result were you looking for?
 
G

Guest

if a starttime is 01:53:00, I would like it displayed as 113:00. However
what I get is 00:00

Marshall Barton said:
Ron said:
In a previous post (which I can't find) I had asked a question about time
being displayed in only minutes and seconds. There was a response about
using the Format command, however I am having problems getting that to work

Mytime = Format(Hour([StartTime])*60 + Minute([StartTime]),"00:") &
Format(Second([StartTime]),"00")

what am I doing wrong with this?


Doesn't look like anything's wrong. What value does
StartTime have? What result were you looking for?
 
K

Ken Snell [MVP]

Original post:

My reply that gave the expression he's now asking about:

--

Ken Snell
<MS ACCESS MVP>


Marshall Barton said:
Ron said:
In a previous post (which I can't find) I had asked a question about time
being displayed in only minutes and seconds. There was a response about
using the Format command, however I am having problems getting that to
work

Mytime = Format(Hour([StartTime])*60 + Minute([StartTime]),"00:") &
Format(Second([StartTime]),"00")

what am I doing wrong with this?


Doesn't look like anything's wrong. What value does
StartTime have? What result were you looking for?
 
K

Ken Snell [MVP]

Ron -

Is the "01:53:00" stored as a text string? or as a date/time value? How to
"convert" it is completely dependent upon the answer. The expression that
I'd posted earlier assumed that you were storing the time value as a
date/time value.

If it's a text string, then this expression should work:

MyTime = Format(CInt(Left([OriginalString], 2)) * 60 +
CInt(Mid([OriginalString], InStr([OriginalString], ":") + 1, 2)), "0:") &
Format(Right([OriginalString], 2), "00")

--

Ken Snell
<MS ACCESS MVP>

Ron P said:
if a starttime is 01:53:00, I would like it displayed as 113:00. However
what I get is 00:00

Marshall Barton said:
Ron said:
In a previous post (which I can't find) I had asked a question about
time
being displayed in only minutes and seconds. There was a response about
using the Format command, however I am having problems getting that to
work

Mytime = Format(Hour([StartTime])*60 + Minute([StartTime]),"00:") &
Format(Second([StartTime]),"00")

what am I doing wrong with this?


Doesn't look like anything's wrong. What value does
StartTime have? What result were you looking for?
 
M

Marshall Barton

Ken said:
Is the "01:53:00" stored as a text string? or as a date/time value? How to
"convert" it is completely dependent upon the answer. The expression that
I'd posted earlier assumed that you were storing the time value as a
date/time value.

If it's a text string, then this expression should work:

MyTime = Format(CInt(Left([OriginalString], 2)) * 60 +
CInt(Mid([OriginalString], InStr([OriginalString], ":") + 1, 2)), "0:") &
Format(Right([OriginalString], 2), "00")


I don't think that's necessary Ken, at least not if : is the
system's time delimiter character. Your original expression
uses the Hour, Minute and Second functions, which will
automatically convert a legal time string to a DateTime
value.

You're probably right about a data type problem, but I would
like to see more of the code to see if the StartTime
variable was ever assigned a value. Some breakpoints might
help illuminate the problem.
 
K

Ken Snell [MVP]

Marshall Barton said:
Ken Snell [MVP] wrote:

at least not if : is the
system's time delimiter character. Your original expression
uses the Hour, Minute and Second functions, which will
automatically convert a legal time string to a DateTime
value.

You're correct, of course....can I plead a "late hour" when I wrote this? <
g >
 
M

Marshall Barton

Ken said:
< snipped >

"Marshall Barton" wrote
Ken said:
You're correct, of course....can I plead a "late hour" when I wrote this?
<g >


But, of course. I often plead all kinds of things and
what's fair for one is fair for all ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top