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

Q: Rounding time

P: n/a
Hi

Is there a way to round up or down time intervals. For example, suppose we
have a variable storing the time 14:06, what is the easiest way to round it
to the nearest minute?

Thanks in advance

Geoff
Nov 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Come again?

14h 6m is rounded to nearest minute.

:^)
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
Hi

Is there a way to round up or down time intervals. For example, suppose we
have a variable storing the time 14:06, what is the easiest way to round it to the nearest minute?

Thanks in advance

Geoff

Nov 20 '05 #2

P: n/a
Apologies, the 14 was minutes and 6 seconds i.e. this would be rounded to 15
minutes.

Geoff
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:uQ*************@TK2MSFTNGP10.phx.gbl...
Come again?

14h 6m is rounded to nearest minute.

:^)
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
Hi

Is there a way to round up or down time intervals. For example, suppose we have a variable storing the time 14:06, what is the easiest way to round

it
to the nearest minute?

Thanks in advance

Geoff


Nov 20 '05 #3

P: n/a
I should apologize. It's Monday. :^)

Your variable, is it just a string or a timespan?

Greg

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
Apologies, the 14 was minutes and 6 seconds i.e. this would be rounded to 15 minutes.

Geoff
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:uQ*************@TK2MSFTNGP10.phx.gbl...
Come again?

14h 6m is rounded to nearest minute.

:^)
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
Hi

Is there a way to round up or down time intervals. For example,
suppose
we have a variable storing the time 14:06, what is the easiest way to
round it
to the nearest minute?

Thanks in advance

Geoff



Nov 20 '05 #4

P: n/a
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
Apologies, the 14 was minutes and 6 seconds i.e. this would be rounded to 15 minutes.


Most rounding routines work on .5 being the next "rounded up" meaning 14.45
would round to 14 but 14.55 would round to 15. If you want everything above
14 (including 14.01) rounded up then just do something:

if int(min) <> min then result = int(min)+1
Nov 20 '05 #5

P: n/a
It could be a date object, string or timespan. Could it be something to do
with a cast?

Geoff

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl...
I should apologize. It's Monday. :^)

Your variable, is it just a string or a timespan?

Greg

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
Apologies, the 14 was minutes and 6 seconds i.e. this would be rounded to
15
minutes.

Geoff
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:uQ*************@TK2MSFTNGP10.phx.gbl...
Come again?

14h 6m is rounded to nearest minute.

:^)
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
> Hi
>
> Is there a way to round up or down time intervals. For example,

suppose
we
> have a variable storing the time 14:06, what is the easiest way to

round it
> to the nearest minute?
>
> Thanks in advance
>
> Geoff
>
>



Nov 20 '05 #6

P: n/a
You have to parse your string to get it into a timespan variable first

(untested)

Function RoundTimeUp(ByVal t As TimeSpan) As TimeSpan
If t.Seconds Mod 60 = 0 Then
Return t
Else
Return New TimeSpan(t.Hours, t.Minutes + 1, 0)
End If
End Function

HTH,
Greg

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
It could be a date object, string or timespan. Could it be something to do
with a cast?

Geoff

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl...
I should apologize. It's Monday. :^)

Your variable, is it just a string or a timespan?

Greg

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
Apologies, the 14 was minutes and 6 seconds i.e. this would be rounded

to
15
minutes.

Geoff
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:uQ*************@TK2MSFTNGP10.phx.gbl...
> Come again?
>
> 14h 6m is rounded to nearest minute.
>
> :^)
>
>
> "Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
> news:40***********************@news.dial.pipex.com ...
> > Hi
> >
> > Is there a way to round up or down time intervals. For example,

suppose
we
> > have a variable storing the time 14:06, what is the easiest way to

round
> it
> > to the nearest minute?
> >
> > Thanks in advance
> >
> > Geoff
> >
> >
>
>



Nov 20 '05 #7

P: n/a
Actually, you don't even need the Mod 60 now that I think about it.
(TimeSpan.Seconds property is always 0-59)

Function RoundTimeUp(ByVal t As TimeSpan) As TimeSpan
If t.Seconds = 0 Then
Return t
Else
Return New TimeSpan(t.Hours, t.Minutes + 1, 0)
End If
End Function

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:eS**************@TK2MSFTNGP09.phx.gbl...
You have to parse your string to get it into a timespan variable first

(untested)

Function RoundTimeUp(ByVal t As TimeSpan) As TimeSpan
If t.Seconds Mod 60 = 0 Then
Return t
Else
Return New TimeSpan(t.Hours, t.Minutes + 1, 0)
End If
End Function

HTH,
Greg

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
It could be a date object, string or timespan. Could it be something to do with a cast?

Geoff

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl...
I should apologize. It's Monday. :^)

Your variable, is it just a string or a timespan?

Greg

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
> Apologies, the 14 was minutes and 6 seconds i.e. this would be rounded
to
15
> minutes.
>
> Geoff
>
>
> "Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
> news:uQ*************@TK2MSFTNGP10.phx.gbl...
> > Come again?
> >
> > 14h 6m is rounded to nearest minute.
> >
> > :^)
> >
> >
> > "Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
> > news:40***********************@news.dial.pipex.com ...
> > > Hi
> > >
> > > Is there a way to round up or down time intervals. For example,
suppose
> we
> > > have a variable storing the time 14:06, what is the easiest way

to round
> > it
> > > to the nearest minute?
> > >
> > > Thanks in advance
> > >
> > > Geoff
> > >
> > >
> >
> >
>
>



Nov 20 '05 #8

P: n/a
Many thanks guys for all your suggestions

Geoff

"Ricky W. Hunt" <rh*****@hotmail.com> wrote in message
news:N9QKc.96445$WX.1459@attbi_s51...
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
Apologies, the 14 was minutes and 6 seconds i.e. this would be rounded
to 15
minutes.
Most rounding routines work on .5 being the next "rounded up" meaning

14.45 would round to 14 but 14.55 would round to 15. If you want everything above 14 (including 14.01) rounded up then just do something:

if int(min) <> min then result = int(min)+1

Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.