|
-
Oct 7th, 2008, 03:45 PM
#1
Thread Starter
Hyperactive Member
DateTime.Parse Problem
Alright, well this code has been working fine for a bit now, I guess since I was selecting double digit numbers in my Month Calendar but now since its in the Single Digits I'm getting a Error and I know why.
vb Code:
Dim testStr As String = DRow.Item("Date (D/M/Y)").ToString()
Dim sr As New SelectionRange()
sr.Start = DateTime.Parse(testStr.Substring(testStr.IndexOf("Start: ") + 7, 10))
sr.End = DateTime.Parse(testStr.Substring(testStr.IndexOf("End: ") + 5, 10))
Where +7 and +5 are right beside it ", 10" thats where my error is. 10 is for Double Digits while 9 is for Single Digits, is it possible for me to figure out this way in a different matter? Heres 2 Examples:
Start: 10/8/2008 End: 10/14/2008 < works with , 10 and nine but only grabs 200 and not the 8
Start: 10/1/2008 End: 10/4/2008 < works with , 9
-
Oct 7th, 2008, 03:56 PM
#2
Re: DateTime.Parse Problem
You split the string by "End:", then work on individual string of the array. Something like this:
Code:
Dim s As String = "Start: 10/8/2008 End: 10/14/2008"
Dim parts() As String = s.Split("End:")
Dim startDate As Date = Date.Parse(parts(0).Replace("Start:", "").Trim())
Dim endDate As Date = Date.Parse(parts(1).Trim())
And of course, you need to implement errror handling to your code, like using Date.TryParse instead of Date.Parse.
Since you know the format of the date, you can also use Date.TryParseExact and pass in the date format.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Oct 7th, 2008, 04:35 PM
#3
Re: DateTime.Parse Problem
Code:
Dim s As String = "Start: 10/8/2008 End: 10/14/2008"
Dim parts() As String
s = s.Replace(" ", " ")
parts = s.Split(" "c)
Dim startDate As Date = Date.Parse(parts(1))
Dim endDate As Date = Date.Parse(parts(3))
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|