473,326 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

converting minutes into hrs mins

Hi folks,

I am returning a value from a db table, which is the number of mins. I
need to convert this to hrs mins which I have done using the following
code, and also displayed it in my grid:

Dim ts As TimeSpan = TimeSpan.FromMinutes(balance)
tempItem.Cells(8).Text = (ts.Hours & ":" & ts.Minutes)

However I have a problem with the minutes, 8:04 is currently displayed
as 8.4, i am using the following code:

Dim Minstring As New StringBuilder
Dim testLength As Integer = CStr(ts.Minutes).Length

If testLength <2 Then
Dim tempMin As String = "0"
tempMin &= ts.Minutes
Minstring.Append(tempMin)
Else
Minstring.Append(ts.Minutes)

End If

!!still displays 8.4, yet this works in a similar project I have when
used exclusively on dates!!

However I also have negative numbers for this value which when
displayed looks like the following:

-1:-23 instead of - 1:23

Does anyone have any ideas on how to remove the " - " sign from mins,
and also put a " 0 " infront of the 4 in 8:4
Any help would be much appreciated,

Cheers,

Simon

Dec 19 '06 #1
3 1750
Hello,

I would write a simple time formatting routine like this:

Private Function FormatTime(ByVal ts As TimeSpan) As String
Return String.Format("{0}:{1:D2}", ts.Hours, ts.Duration.Minutes)
End Function

Kelly

si_owen wrote:
Hi folks,

I am returning a value from a db table, which is the number of mins. I
need to convert this to hrs mins which I have done using the following
code, and also displayed it in my grid:

Dim ts As TimeSpan = TimeSpan.FromMinutes(balance)
tempItem.Cells(8).Text = (ts.Hours & ":" & ts.Minutes)

However I have a problem with the minutes, 8:04 is currently displayed
as 8.4, i am using the following code:

Dim Minstring As New StringBuilder
Dim testLength As Integer = CStr(ts.Minutes).Length

If testLength <2 Then
Dim tempMin As String = "0"
tempMin &= ts.Minutes
Minstring.Append(tempMin)
Else
Minstring.Append(ts.Minutes)

End If

!!still displays 8.4, yet this works in a similar project I have when
used exclusively on dates!!

However I also have negative numbers for this value which when
displayed looks like the following:

-1:-23 instead of - 1:23

Does anyone have any ideas on how to remove the " - " sign from mins,
and also put a " 0 " infront of the 4 in 8:4
Any help would be much appreciated,

Cheers,

Simon
Dec 19 '06 #2
sorted out the 0 in 8:04

just the - sign now

so -7:-34 shud be -7:34

Dec 19 '06 #3
si_owen wrote:
sorted out the 0 in 8:04

just the - sign now

so -7:-34 shud be -7:34
Use the Math.Abs() function to convert the negative value to a positive one.
Wrap this around the code you're using to extract the minutes from your
TimeSpan and hopefully that'll sort this problem out for you.

--

(O)enone

Dec 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hans [DiaGraphIT] | last post by:
Hi! I have a logical problem. How can I convert 2 textboxvalues,(one for hours and one for minutes) to a common value type of float or double. I wish to save this new value in a database ...
6
by: Harlin Seritt | last post by:
I would like to take milliseconds and convert it to a more human-readable format like: 4 days 20 hours 10 minutes 35 seconds Is there something in the time module that can do this? I havent...
2
by: Harlin Seritt | last post by:
How can I take a time given in milliseconds (I am doing this for an uptime script) and convert it to human-friendly time i.e. "4 days, 2 hours, 25 minutes, 10 seonds."? Is there a function from the...
4
by: TonyB | last post by:
We are calling a webservice running under SSL with a request that takes quite a while (8-12 mins) to return. This has been running fine on my desktop machine for some time now, but when the code is...
5
by: Lad | last post by:
Hello, what is the best /easest way how to get number of hours and minutes from a timedelta object? Let's say we have aa=datetime.datetime(2006, 7, 29, 16, 13, 56, 609000)...
3
by: Golan | last post by:
Hi all, I need to write a code which gets a date (in format 'YYYYMMDDhh24MISS') and number of seconds (X), and returns the date (again in format 'YYYYMMDDHH24MISS') that is X seconds prior to...
8
by: mdburton | last post by:
I don't knwo if this is the correct forum, but ill assume so since it is running php scripts ; ) Anyways I need a script to run every 10 mins on the 5, so :05, :15, :25,:35,:45,:55 I know the...
3
by: Sean Farrow | last post by:
Hi: I have the folling code: def parseTime(self, time): minutes =int(float(time)/60) seconds =int(float(time)-minutes*60) minutes =str(minutes) seconds =str(minutes) the statements that...
2
by: mar10 | last post by:
i have TIME WORKED stored as minutes - I'd like to convert this to days,hours,minutes. I'm currently converting to hours and minutes but have not had success adding the days portion to the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.