Link to home
Start Free TrialLog in
Avatar of NursingCorp
NursingCorpFlag for United States of America

asked on

VB.NET parse datetime string to get just time

Assistance getting a value out of a datetime string using VB.NET,

We start with a string for the startTime = 1/8/2009 5:30:00 AM

How do I  parse this string to get the hour of the time (i.e. 5)
then, parse the string to get the minutes (i.e. 30)
then, parse the string to get the AM/PM part

and then convert it based on,
 
if the minutes = 00, set the newStartTime = 5.0
if the minutes = 30 set the newStartTime = 5.5
if the AM/PM were PM, then add 12 to hours so that newStartTime = 17.5

I am new to computer programming, and have been trying to learn via books and online videos.

Thanks,
Joe


Avatar of MikeDiehn
MikeDiehn
Flag of United States of America image

This is a good article about the date time functions you have access to in VB.NET:

  http://articles.techrepublic.com.com/5100-10878_11-6089546.html

Here is an example they gave:
  Dim Hour As DateTime = DateTime.Hour
  MessageBox.Show(Hour)

ASKER CERTIFIED SOLUTION
Avatar of thefarm
thefarm
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NursingCorp

ASKER

Thanks everyone.