[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 912
  • Last Modified:

vb.net convert 24 hour to 12 hour

trying to figure out how to convert a record stored as 24 hour in db to 12 hour when displayed in my program.   Among other things I have tried the following code:

Dim strTime As String = String.Format("{0:hh:mm tt}", CloseTime)

Open in new window


This still gives 24 hour time.   Any help is appreciated.
0
McGurk1
Asked:
McGurk1
  • 3
  • 2
  • 2
1 Solution
 
McGurk1Author Commented:
have also tried:

strTime = CloseTime.ToString("hh:mm AMPM")

Open in new window

0
 
lluddenCommented:
What is the datatype of Closetime?
0
 
McGurk1Author Commented:
datatype is time(7)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Carlos VillegasFull Stack .NET DeveloperCommented:
Try:
Dim strTime As String = String.Format("{0:h:mm tt}", CloseTime)

Or this:
Dim strTime As String = Convert.ToDateTime(CloseTime).ToString("h:mm tt");
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Or this too:
Dim strTime As String = CloseTime.ToString("h:mm tt");
0
 
lluddenCommented:
Cast it as a date and try it.

Dim strTime As String = String.Format("{0:hh:mm tt}", CDate(CloseTime))
0
 
McGurk1Author Commented:
Thanks for all of the help.  Tried all of the suggestions.  lludden's worked when I cast it to a date first..

my final code:
Dim dtTime as Date = CDate(CloseTime)
Dim strTime as String = String.Format("{0:h:mm tt}", dtTime)

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now