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

Decode Unusual Timespan

I have a 'timespan' which is specified in an unusual way. For example, to
specify 47 hours and 26 minutes, the timepsan is specified as

47:26

If I use Timespen.TryParse on this then, of course, it fails. Can anyone
think of a neat way to decode timespans specified in this way? I also have
timespans specified as

3.30

which would mean 3hrs and 30 minutes.

I realise that I could split the values and format my own timespan, but I am
wondering if there is a one-liner built-in.

TIA

Charles
Sep 16 '08 #1
2 948
Then create a function and reuse at will ? It could give something such as
(checking code left out) :

Shared Function ToTimeSpan(ByVal s As String, Optional ByVal sep As Char
= ":"c) As TimeSpan
Dim v() As String
v = s.Split(sep)
Dim t As New TimeSpan(CInt(v(0)), CInt(v(1)), 0)
Return t
End Function

Shared Sub Main()
MsgBox(ToTimeSpan("47:26").ToString)
MsgBox(ToTimeSpan("3.30", "."c).ToString)
End Sub

--
Patrice

"Charles Law" <bl***@nowhere.coma écrit dans le message de groupe de
discussion : e4**************@TK2MSFTNGP03.phx.gbl...
I have a 'timespan' which is specified in an unusual way. For example, to
specify 47 hours and 26 minutes, the timepsan is specified as

47:26

If I use Timespen.TryParse on this then, of course, it fails. Can anyone
think of a neat way to decode timespans specified in this way? I also have
timespans specified as

3.30

which would mean 3hrs and 30 minutes.

I realise that I could split the values and format my own timespan, but I
am wondering if there is a one-liner built-in.

TIA

Charles

Sep 17 '08 #2
Hi Patrice

Thanks for the reply. From that I read that there is no one-liner, so I am
stuck with rolling my own, as you say.

Cheers

Charles
"Patrice" <http://www.chez.com/scribe/wrote in message
news:Or**************@TK2MSFTNGP03.phx.gbl...
Then create a function and reuse at will ? It could give something such as
(checking code left out) :

Shared Function ToTimeSpan(ByVal s As String, Optional ByVal sep As
Char = ":"c) As TimeSpan
Dim v() As String
v = s.Split(sep)
Dim t As New TimeSpan(CInt(v(0)), CInt(v(1)), 0)
Return t
End Function

Shared Sub Main()
MsgBox(ToTimeSpan("47:26").ToString)
MsgBox(ToTimeSpan("3.30", "."c).ToString)
End Sub

--
Patrice

"Charles Law" <bl***@nowhere.coma écrit dans le message de groupe de
discussion : e4**************@TK2MSFTNGP03.phx.gbl...
>I have a 'timespan' which is specified in an unusual way. For example, to
specify 47 hours and 26 minutes, the timepsan is specified as

47:26

If I use Timespen.TryParse on this then, of course, it fails. Can anyone
think of a neat way to decode timespans specified in this way? I also
have timespans specified as

3.30

which would mean 3hrs and 30 minutes.

I realise that I could split the values and format my own timespan, but I
am wondering if there is a one-liner built-in.

TIA

Charles


Sep 17 '08 #3

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

Similar topics

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: Ivan A. | last post by:
Hi! Why I can't serialize TimeSpan structure with XmlSerializer? This is what I do: using System; using System.IO; using System.Xml; using System.Xml.Serialization;
2
by: DWalker | last post by:
In Visual Studio (Visual Basic) .NET 2002, I noticed that this: Dim Elapsed as DateTime = Now - Now gives a "compile time" error (error in the IDE), saying that the '-' operator is not...
10
by: Charles Law | last post by:
If I display a TimeSpan I get something like 00:05:17.6217891 when what I would like to see is 00:05:18 Is there an easy way to get this output? Try as I might I just can't find it.
2
by: ucasesoftware | last post by:
i translate a C# funtion to VB.NET and i have this : Shared Function isAllDay(ByVal ap As Appointment) As Boolean Return ap.DateBegin.TimeOfDay = TimeSpan.Zero AndAlso ap.DateEnd.TimeOfDay =...
13
by: sd00 | last post by:
Hi all, can someone give me some coding help with a problem that *should* be really simple, yet I'm struggling with. I need the difference between 2 times (Target / Actual) However, these times...
7
by: brett.estabrook | last post by:
I have written a multi-threaded c# windows service in .net 1.1 (Visual Studio .net 2003). The service has several threads that poll a Sql 6.5 database on another machine. Each thread will execute a...
4
by: Massimo | last post by:
Hi to All, i'm using C# in .NET 2.0 and i have a DataTable A with a column of type TimeSpan used to store HOUR info. I'm trying to filter my DataTable A selecting only rows that have the column...
2
by: Charles Law | last post by:
I have a 'timespan' which is specified in an unusual way. For example, to specify 47 hours and 26 minutes, the timepsan is specified as 47:26 If I use Timespen.TryParse on this then, of...
3
by: Gilles Ganault | last post by:
Hello I'm getting this error while downloading and parsing web pages: ===== title = m.group(1) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 48: ordinal not in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.