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 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
sorted out the 0 in 8:04
just the - sign now
so -7:-34 shud be -7:34
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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
...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
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...
| |