Author |
Topic |
saidev
Posting Yak Master
101 Posts |
Posted - 2006-09-22 : 13:25:08
|
Hi Guys,I have a problem with the Time Format. when i import the text file into the table the time i am getting is 1320. Can you guys help me how to convert this into 01:20:00P. Appreciate your help.I want to change this in my VB.NET Code.Thanks |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-09-22 : 14:21:14
|
[code]public function FormatTime(string old) as String Dim AMPM as String = "A" Dim H as Integer = Integer.Parse(old.substring(0,2)) Dim M as Integer = Integer.Parse(old.substring(2,2)) If H > 12 Then AMPM = "P" H = H - 12 End Return H.ToString("00") & ":" & M.ToString("00") & ":00" & AMPMEnd Function[/code]typed by hand, not tested, hopefully you can follow that and get the idea. I suspect, of course, that there is more to the question than you asked.- Jeff |
 |
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-09-22 : 14:22:14
|
saidev - we're not mind-readers or psychics, if you want us to help you'll need to give the code you're using and the database table structure. |
 |
|
saidev
Posting Yak Master
101 Posts |
Posted - 2006-09-22 : 14:45:09
|
quote: Originally posted by jsmith8858
public function FormatTime(string old) as String Dim AMPM as String = "A" Dim H as Integer = Integer.Parse(old.substring(0,2)) Dim M as Integer = Integer.Parse(old.substring(2,2)) If H > 12 Then AMPM = "P" H = H - 12 End Return H.ToString("00") & ":" & M.ToString("00") & ":00" & AMPMEnd Function typed by hand, not tested, hopefully you can follow that and get the idea. I suspect, of course, that there is more to the question than you asked.- Jeff
Hi Jeff,I tried this in my VB.NET Code. But i am getting the Error"input string was not in a correct format". please adviseThanks, Public Function FormatTime(ByVal old) As String Try Dim AMPM As String = "A" Dim H As Integer = Integer.Parse(old.substring(0, 2)) Dim M As Integer = Integer.Parse(old.substring(2, 2)) If H > 12 Then AMPM = "P" H = H - 12 End If Return H.ToString("00") & ":" & M.ToString("00") & ":00" & AMPM Catch ex As Exception End Try End Function |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
saidev
Posting Yak Master
101 Posts |
Posted - 2006-09-22 : 15:13:08
|
I did change to VB.NET but still i am gettin the Error"Input String was not in a correct Format". Can some one pls advise what is wrong..Thanks,Public Function FormatTime(ByVal old) As String Try Dim AMPM As String = "A" Dim H As Integer = Integer.Parse(old.substring(0, 2)) Dim M As Integer = Integer.Parse(old.substring(2, 2)) If H > 12 Then AMPM = "P" H = H - 12 End If Return H.ToString("00") & ":" & M.ToString("00") & ":00" & AMPM Catch ex As Exception End Try End Function |
 |
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-09-22 : 15:14:08
|
quote: Why is that needed for a VB.NET question?
Because the original post said "when i import the text file into the table" - given that this is an ASP.NET forum, and the question mentions "text file", "the table" and "my VB.NET code", without mentioning where the converted value is going - you're welcome to guess what they're really asking. |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-09-22 : 15:15:00
|
quote: Originally posted by saidev I did change to VB.NET but still i am gettin the Error"Input String was not in a correct Format". Can some one pls advise what is wrong..Thanks,Public Function FormatTime(ByVal old as string) As String Try Dim AMPM As String = "A" Dim H As Integer = Integer.Parse(old.substring(0, 2)) Dim M As Integer = Integer.Parse(old.substring(2, 2)) If H > 12 Then AMPM = "P" H = H - 12 End If Return H.ToString("00") & ":" & M.ToString("00") & ":00" & AMPM Catch ex As Exception End Try End Function
My VB and C# got mixed up in my original code on the parameters args ... see the bold, above .... By the way -- you should always have OPTION STRICT ON to avoid errors like what you are getting, that forces you to declare data types.- Jeff |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-09-22 : 15:23:24
|
quote: Originally posted by snSQL
quote: Why is that needed for a VB.NET question?
Because the original post said "when i import the text file into the table" - given that this is an ASP.NET forum, and the question mentions "text file", "the table" and "my VB.NET code", without mentioning where the converted value is going - you're welcome to guess what they're really asking.
It looks to me like the poster did say where the converted value is going. The data is beng sent from the database as 1320. saidev wanted to know how to convert it in VB.NET to 01:20:00P.But perhaps I'm not reading the poster correctly. I assumed the above due to it being in the ASP.NET forum and the wording of the post.Tara Kizer |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-09-22 : 15:45:55
|
Any way you slice it, this question left a lot open to interpretation. I am quite sure that while I provided a function that did exactly what he asked there is much more to the story.I sure hope that he has finally listened and decided to start using proper datatypes for his table columns, but somehow I doubt it. - Jeff |
 |
|
saidev
Posting Yak Master
101 Posts |
Posted - 2006-09-22 : 15:53:26
|
quote: Originally posted by jsmith8858
quote: Originally posted by saidev I did change to VB.NET but still i am gettin the Error"Input String was not in a correct Format". Can some one pls advise what is wrong..Thanks,Public Function FormatTime(ByVal old as string) As String Try Dim AMPM As String = "A" Dim H As Integer = Integer.Parse(old.substring(0, 2)) Dim M As Integer = Integer.Parse(old.substring(2, 2)) If H > 12 Then AMPM = "P" H = H - 12 End If Return H.ToString("00") & ":" & M.ToString("00") & ":00" & AMPM Catch ex As Exception End Try End Function
My VB and C# got mixed up in my original code on the parameters args ... see the bold, above .... By the way -- you should always have OPTION STRICT ON to avoid errors like what you are getting, that forces you to declare data types.- Jeff
Hi Jeff,Appreciate your help,Thanks |
 |
|
|