Showing posts with label seconds. Show all posts
Showing posts with label seconds. Show all posts

Monday, March 19, 2012

Displaying seconds value as [mm]:ss

Hello
I am returning a int value from a database which is for an elasped
time in seconds. I want to convert this to mm:ss, however I dont want
it roll over to hours or days.
I trying something along the lines of:
=String.Format("{0:0:mm:ss}",CDate("0:0:0").AddSeconds(Sum(Fields!Airtime.Value)))
However this still allows values to go to hours/days, just doesn't
display them
So for example a value returned from the database of 19257 (seconds)
should be displayed as 320:57 ([mm]:ss)
This is achived in excel by
19257 / 24 = 802.375 / 60 = 13.37291667 /60 = 0.222881944
Then change the format on the cell to [mm]:ss
Then 320:57 is displayed.
Any ideas would be great
Thanks
DavidYou could create custom function, something like this:
Function Seconds2mmss(ByVal seconds As Integer) As String
Dim ss As Integer = seconds Mod 60
Dim mm As Integer = seconds - ss * 60
Seconds2mmss = String.Format("{0:0}:{1:00}", mm, ss)
End Function
and then call it from textbox expression:
=Code.Seconds2mmss(Sum(Fields!Airtime.Value))
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"David" <david.glasgow@.unison.co.nz> wrote in message
news:9f43b964.0408112015.79b5c9b9@.posting.google.com...
> Hello
> I am returning a int value from a database which is for an elasped
> time in seconds. I want to convert this to mm:ss, however I dont want
> it roll over to hours or days.
> I trying something along the lines of:
> =String.Format("{0:0:mm:ss}",CDate("0:0:0").AddSeconds(Sum(Fields!Airtime.Value)))
> However this still allows values to go to hours/days, just doesn't
> display them
> So for example a value returned from the database of 19257 (seconds)
> should be displayed as 320:57 ([mm]:ss)
> This is achived in excel by
> 19257 / 24 = 802.375 / 60 = 13.37291667 /60 = 0.222881944
> Then change the format on the cell to [mm]:ss
> Then 320:57 is displayed.
> Any ideas would be great
> Thanks
> David|||Thanks for that, the final code that returned the result was:
Function Seconds2mmss(ByVal seconds As Integer) As String
Dim ss As Integer = seconds Mod 60
Dim mm As Integer = (seconds - ss) / 60
Seconds2mmss = String.Format("{0:0}:{1:00}", mm, ss)
End Function
Thanks again for your help

Sunday, March 11, 2012

displaying milliseconds in VB 6 program

Hi,
I am trying to get my VB program to recognize milliseconds when it is
returned as a datetime field from sql. I can format it to the seconds but
can't find out to include the milliseconds. Any help would be appreciated.
EllieReturn a CHAR/VARCHAR from SQL Server (using CONVERT()) and explicitly cast
the result as a string in VB (CStr() I guess). You could also write a
simple date formatting function in VB, but if you're getting short-circuited
by VB somehow and it trims them off, only if you return the milliseconds
separately. Some of these articles might be helpful:
http://www.aspfaq.com/2460
http://www.aspfaq.com/2313
http://www.aspfaq.com/2093
"Ellie" <nospam@.nospam.net> wrote in message
news:O88yFBXkGHA.3816@.TK2MSFTNGP02.phx.gbl...
> Hi,
> I am trying to get my VB program to recognize milliseconds when it is
> returned as a datetime field from sql. I can format it to the seconds but
> can't find out to include the milliseconds. Any help would be appreciated.
> Ellie
>