473,395 Members | 1,386 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,395 software developers and data experts.

timespan.parse question

Hi group, it's been a long time since the last time I've been here but I
have a question.

I'm working with timespan.parse for calculating a duration, I have to add
strings which are in the following format 15:36:12 ==Hours, minutes,
seconds
but sometimes there is a string like 55:26:32 ==which is correct cause
the production machine was busy for 55 hours, but the timespan.parse crashes
on this value because it expects 2.7:26:32. I've written the following
function to convert 55:26:32 to 2.7:26:32 but I would like to know if there
isn't a built in function for this in .net 2003

Private Function ConvertToReadableString(ByVal input As String) As String
Dim strParts(2) As String
Dim intDays As Integer
Dim intHours As Integer

strParts = input.Split(":"c)

If CInt(strParts(0)) 24 Then
intDays = CInt(Math.Floor(CInt(strParts(0)) / 24))
intHours = CInt(strParts(0)) Mod 24
Return CStr(intDays) & "." & CStr(intHours) & ":" & strParts(1)
& ":" & strParts(2)
Else
Return input
End If
End Function
Thanks

Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)
Jan 16 '07 #1
4 3267
Hi Peter,

At the last moment I maybe found something, but I have no time to test.

Can you not investigate how many hours are involved subtract the multiple of
days to 24 from the timespan and than, I assume that you know the rest what
I mean. (If not reply)

http://msdn2.microsoft.com/en-us/lib...pan.hours.aspx

http://msdn2.microsoft.com/en-us/lib...espan.add.aspx

55/24 = 2 plus rest hours.

Cor

"Peter Proost" <pp*****@nospam.hotmail.comschreef in bericht
news:%2***************@TK2MSFTNGP04.phx.gbl...
Hi group, it's been a long time since the last time I've been here but I
have a question.

I'm working with timespan.parse for calculating a duration, I have to add
strings which are in the following format 15:36:12 ==Hours, minutes,
seconds
but sometimes there is a string like 55:26:32 ==which is correct cause
the production machine was busy for 55 hours, but the timespan.parse
crashes
on this value because it expects 2.7:26:32. I've written the following
function to convert 55:26:32 to 2.7:26:32 but I would like to know if
there
isn't a built in function for this in .net 2003

Private Function ConvertToReadableString(ByVal input As String) As String
Dim strParts(2) As String
Dim intDays As Integer
Dim intHours As Integer

strParts = input.Split(":"c)

If CInt(strParts(0)) 24 Then
intDays = CInt(Math.Floor(CInt(strParts(0)) / 24))
intHours = CInt(strParts(0)) Mod 24
Return CStr(intDays) & "." & CStr(intHours) & ":" & strParts(1)
& ":" & strParts(2)
Else
Return input
End If
End Function
Thanks

Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)


Jan 18 '07 #2
Hi Cor I understand what you want to say. I also get why .net thinks more
than 23 hours is wrong in a datetime, but in my opinion more than 23 hours
should be allowed in a timespan, but that's probably just because I need it
now ;-)

Thanks Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:OK**************@TK2MSFTNGP02.phx.gbl...
Hi Peter,

At the last moment I maybe found something, but I have no time to test.

Can you not investigate how many hours are involved subtract the multiple
of
days to 24 from the timespan and than, I assume that you know the rest
what
I mean. (If not reply)

http://msdn2.microsoft.com/en-us/lib...pan.hours.aspx

http://msdn2.microsoft.com/en-us/lib...espan.add.aspx

55/24 = 2 plus rest hours.

Cor

"Peter Proost" <pp*****@nospam.hotmail.comschreef in bericht
news:%2***************@TK2MSFTNGP04.phx.gbl...
Hi group, it's been a long time since the last time I've been here but I
have a question.

I'm working with timespan.parse for calculating a duration, I have to
add
strings which are in the following format 15:36:12 ==Hours, minutes,
seconds
but sometimes there is a string like 55:26:32 ==which is correct
cause
the production machine was busy for 55 hours, but the timespan.parse
crashes
on this value because it expects 2.7:26:32. I've written the following
function to convert 55:26:32 to 2.7:26:32 but I would like to know if
there
isn't a built in function for this in .net 2003

Private Function ConvertToReadableString(ByVal input As String) As
String
Dim strParts(2) As String
Dim intDays As Integer
Dim intHours As Integer

strParts = input.Split(":"c)

If CInt(strParts(0)) 24 Then
intDays = CInt(Math.Floor(CInt(strParts(0)) / 24))
intHours = CInt(strParts(0)) Mod 24
Return CStr(intDays) & "." & CStr(intHours) & ":" &
strParts(1)
& ":" & strParts(2)
Else
Return input
End If
End Function
Thanks

Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to
produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)


Jan 18 '07 #3
Don't panic Peter. You are correct, the TimeSpan.Oarse method will spit it's
dummy on "55:26:32", but there is a constructor for TimeSpan that takes,
hours 23, minutes 60 and seconds 60:

You still need to split the source and convert.to integers though:

Private Function ConvertToTimeSpan(ByVal input As String) As TimeSpan

Dim _parts As String() = input.Split(":"c)

Return New TimeSpan(Integer.Parse(_parts(0)), Integer.Parse(_parts(1)),
Integer.Parse(_parts(2)))

End Sub
"Peter Proost" <pp*****@nospam.hotmail.comwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
Hi group, it's been a long time since the last time I've been here but I
have a question.

I'm working with timespan.parse for calculating a duration, I have to add
strings which are in the following format 15:36:12 ==Hours, minutes,
seconds
but sometimes there is a string like 55:26:32 ==which is correct cause
the production machine was busy for 55 hours, but the timespan.parse
crashes
on this value because it expects 2.7:26:32. I've written the following
function to convert 55:26:32 to 2.7:26:32 but I would like to know if
there
isn't a built in function for this in .net 2003

Private Function ConvertToReadableString(ByVal input As String) As String
Dim strParts(2) As String
Dim intDays As Integer
Dim intHours As Integer

strParts = input.Split(":"c)

If CInt(strParts(0)) 24 Then
intDays = CInt(Math.Floor(CInt(strParts(0)) / 24))
intHours = CInt(strParts(0)) Mod 24
Return CStr(intDays) & "." & CStr(intHours) & ":" & strParts(1)
& ":" & strParts(2)
Else
Return input
End If
End Function
Thanks

Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)


Jan 18 '07 #4
Thanks Stephany, I didn't try that because I overlooked it.

thanks for the help

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"Stephany Young" <noone@localhostschreef in bericht
news:uO**************@TK2MSFTNGP03.phx.gbl...
Don't panic Peter. You are correct, the TimeSpan.Oarse method will spit
it's
dummy on "55:26:32", but there is a constructor for TimeSpan that takes,
hours 23, minutes 60 and seconds 60:

You still need to split the source and convert.to integers though:

Private Function ConvertToTimeSpan(ByVal input As String) As TimeSpan

Dim _parts As String() = input.Split(":"c)

Return New TimeSpan(Integer.Parse(_parts(0)),
Integer.Parse(_parts(1)),
Integer.Parse(_parts(2)))

End Sub
"Peter Proost" <pp*****@nospam.hotmail.comwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
Hi group, it's been a long time since the last time I've been here but I
have a question.

I'm working with timespan.parse for calculating a duration, I have to
add
strings which are in the following format 15:36:12 ==Hours, minutes,
seconds
but sometimes there is a string like 55:26:32 ==which is correct
cause
the production machine was busy for 55 hours, but the timespan.parse
crashes
on this value because it expects 2.7:26:32. I've written the following
function to convert 55:26:32 to 2.7:26:32 but I would like to know if
there
isn't a built in function for this in .net 2003

Private Function ConvertToReadableString(ByVal input As String) As
String
Dim strParts(2) As String
Dim intDays As Integer
Dim intHours As Integer

strParts = input.Split(":"c)

If CInt(strParts(0)) 24 Then
intDays = CInt(Math.Floor(CInt(strParts(0)) / 24))
intHours = CInt(strParts(0)) Mod 24
Return CStr(intDays) & "." & CStr(intHours) & ":" &
strParts(1)
& ":" & strParts(2)
Else
Return input
End If
End Function
Thanks

Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to
produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)


Jan 18 '07 #5

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

Similar topics

9
by: ThunderMusic | last post by:
Hi, I'm using the timespan's Parse method to build my timespan from a string. here's the line I use : m_Delay.Parse(RegKey.GetValue("Delay", "01:00:00")) the value I get from the RegKey is...
5
by: Dirk Reske | last post by:
hey, when I do: TimeSpan ts = TimeSpan.FromTicks(System.Enviroment.TickCount); ts.ToString(); I get something like this: 00:00:00.2381474 but I want to see, how many hours,...
1
by: Doug | last post by:
Hi, I was wondering if someone could tell me how i can convert a value that's a string into a TimeSpan? Thanks, Doug
2
by: Jeff Shantz | last post by:
Hello, I'm developing a large statistics application for a call center. It often needs to calculate time spanning over months. For example, an agent's total talk time within 30 days. Since an...
3
by: Horselover Fat | last post by:
Hi, I have a column in a database that holds elapsed time in milliseconds and I want to display that column in a DataGrid in a specific format (d.hh:mm:ss.fff). However, the closest I can get...
3
by: Lars Schouw | last post by:
I would like to to add a time span "1Y 2M 3W 20D" entered as a string to a date time how do I do that? Lars
5
by: | last post by:
Why is it that: DateTime start = DateTime.Parse("1:00 AM"); DateTime stop = DateTime.Parse("2:30 AM"); TimeSpan ts = stop - start; Response.Write(ts.Minutes.ToString()); Produces 30, not 90?...
4
by: kellygreer1 | last post by:
I haven't worked with the TimeSpan object before. So bare with me if this seems like a newb question. But if I wanted to know how many days from the current date until 2/4/2008. I have written...
2
by: =?Utf-8?B?WVhR?= | last post by:
Hello, I want to convert the timespan (1.12:25:23) to 1day 12hour 25min 23sec, how to do it? thank you.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.