By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 2,138 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

Parse Seconds to Time AM/PM

P: n/a
Banging my head here. I have an older Database that I have imported to Access and the original database system (Dataflex)
stored the Time of Day in Seconds. I can use :TimeSpan.FromSeconds(74400),, to get a time of: 20:40 (24hr time).
I need to get 8:40 PM . But, looking thru all the different methods of TimeSpan I cannot find how this is done short of writing
a routine that looks at the Hours and Seconds to determine AM/PM . I also looked thru the DateTime function and although it
will accept Seconds, it
shows : 01/01/0001 02:04 (if I remember correctly) which is the date and time from the beginning of time
( VB.NET time) I have looked at the Parse method and cannot find any examples on how this is done.
And Google doesn't seem to find anything either.
I would think there would be a simple parsing method that would allow you to display the time as 12Hr. or 24Hr time. But, I
cannot find anything to show that.
Any info would be greatly appreciated.
james

(I'm betting it's going to be simple)
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
james wrote:
looked thru the DateTime function and although it
will accept Seconds, it
shows : 01/01/0001 02:04 (if I remember correctly) which is the date and time from the beginning of time
I would think there would be a simple parsing method that would allow you to display the time as 12Hr. or 24Hr time. But, I


A DateTime variable will always have both a date and time component.
To display just the time, use the ToString method of the DateTime
variable:

Dim dtCurrTime As New DateTime(0,0,0,0,0,74400)

MsgBox("Current Time is: " & dtCurrTime.ToString("hh:mm tt"))

'Result: Current Time is: 08:40 PM

MsgBox("Current Time is: " & dtCurrTime.ToString("HH:mm"))

'Result: Current Time is: 20:40

HTH

Chris

Nov 21 '05 #2

P: n/a
"Chris Dunaway" <du******@gmail.com> wrote in message news:11*********************@g43g2000cwa.googlegro ups.com...
james wrote:
looked thru the DateTime function and although it
will accept Seconds, it
shows : 01/01/0001 02:04 (if I remember correctly) which is the date and time from the beginning of time
I would think there would be a simple parsing method that would allow you to display the time as 12Hr. or 24Hr time. But, I


A DateTime variable will always have both a date and time component.
To display just the time, use the ToString method of the DateTime
variable:

Dim dtCurrTime As New DateTime(0,0,0,0,0,74400)

MsgBox("Current Time is: " & dtCurrTime.ToString("hh:mm tt"))

'Result: Current Time is: 08:40 PM

MsgBox("Current Time is: " & dtCurrTime.ToString("HH:mm"))

'Result: Current Time is: 20:40

HTH

Chris


Chris, thanks for the info, using the example code, I get : Specified argument was out of the range of valid values. Which
doesn't make sense to me as there are 86,400 seconds in a 24 hr period. So, as your example shows, it should show the time
correctly as 74400 is not out of range. Maybe, I copied something wrong.
I will keep playing with it.
james


Nov 21 '05 #3

P: n/a

"Chris Dunaway" <du******@gmail.com> wrote in message news:11*********************@g43g2000cwa.googlegro ups.com...
A DateTime variable will always have both a date and time component.
To display just the time, use the ToString method of the DateTime
variable:

Dim dtCurrTime As New DateTime(0,0,0,0,0,74400)

MsgBox("Current Time is: " & dtCurrTime.ToString("hh:mm tt"))

'Result: Current Time is: 08:40 PM

MsgBox("Current Time is: " & dtCurrTime.ToString("HH:mm"))

'Result: Current Time is: 20:40

HTH

Chris


Chris, just an update, I even copied and pasted this code:

Dim dtCurrTime As New DateTime(0,0,0,0,0,74400)

MsgBox("Current Time is: " & dtCurrTime.ToString("hh:mm tt"))
And got this error:

"An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

Additional information: Specified argument was out of the range of valid values."
If I put it in a Try-Catch block it shows this error:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.

Parameter name: Year, Month, and Day parameters describe an unrepresentable DateTime.

at System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day)

at System.DateTime..ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second)

at Seconds_to_Time.Form1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\James\My Documents\Visual Studio
Projects\VS2003Beta\Seconds to Time\Seconds to Time\Form1.vb:line 112
So, I am a bit lost as what to do. Just thought you might want to see the results I have got.
Thanks for your help.
james

Nov 21 '05 #4

P: n/a
james wrote:
"Chris Dunaway" <du******@gmail.com> wrote in message news:11*********************@g43g2000cwa.googlegro ups.com...

Dim dtCurrTime As New DateTime(0,0,0,0,0,74400)

MsgBox("Current Time is: " & dtCurrTime.ToString("hh:mm tt"))

'Result: Current Time is: 08:40 PM

MsgBox("Current Time is: " & dtCurrTime.ToString("HH:mm"))

'Result: Current Time is: 20:40

HTH

Chris


I'm sorry, that is what I call thin air code. Change the declaration
to:

Dim dtCurrTime As new DateTime(1,1,1,0,0,74400)

That sets the date portion to a valid date of jan 1, 0001. When you do
the format, it only gets the time. Or you can use the TimeValue
property of the DateTime.

Nov 21 '05 #5

P: n/a

"Chris Dunaway" <du******@gmail.com> wrote in message news:11**********************@g49g2000cwa.googlegr oups.com...

I'm sorry, that is what I call thin air code. Change the declaration
to:

Dim dtCurrTime As new DateTime(1,1,1,0,0,74400)

That sets the date portion to a valid date of jan 1, 0001. When you do
the format, it only gets the time. Or you can use the TimeValue
property of the DateTime.


There must be something in my system setup that is causing this, using the same declaration that you included here, I still get
the same error messages. I do appreciate your help. I will eventually track this
problem down and once I do, I will post a follow-up.
james
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.