Solved

Format String to Date

Posted on 2004-10-14
10
173 Views
Last Modified: 2012-05-05
I have:

Dim strDate As String = Month.Selection.Text & "/" & Day.Selection.Text & "/" & Year.Selection.Text

I need to convert the "Month" to numeric.  ex:

Currently it comes out:
OCT/14/2004

I want:
10/14/2004

?? help!  THANKS!
0
Comment
Question by:sticar
10 Comments
 
LVL 8

Expert Comment

by:bramsquad
Comment Utility
what control does

Month.Selection.Text

come from?
0
 

Author Comment

by:sticar
Comment Utility
Protected WithEvents Month As System.Web.UI.MobileControls.SelectionList
0
 
LVL 8

Expert Comment

by:bramsquad
Comment Utility
if you have all months in a selection list how does accessing the Index work?

Cstr(Month.SelectedIndex)

or

Cstr(Month.SelectedIndex + 1)

depending on the index

~b
0
 

Author Comment

by:sticar
Comment Utility
I think I can do this:
Month.Selection.Value

<mobile:SelectionList id="Month" title="Pickup Month" Wrapping="NoWrap" Font-Size="Small" Alignment="Left" runat="server">
      <Item Value="1" Text="JAN"></Item>
      <Item Value="2" Text="FEB"></Item>
      <Item Value="3" Text="MAR"></Item>
      <Item Value="4" Text="APR"></Item>
      <Item Value="5" Text="MAY"></Item>
      <Item Value="6" Text="JUN"></Item>
      <Item Value="7" Text="JUL"></Item>
      <Item Value="8" Text="AUG"></Item>
      <Item Value="9" Text="SEP"></Item>
      <Item Value="10" Text="OCT"></Item>
      <Item Value="11" Text="NOV"></Item>
      <Item Value="12" Text="DEC"></Item>
</mobile:SelectionList>
0
 

Author Comment

by:sticar
Comment Utility
What about a string that = "1:00 PM" or "1:00 AM" to change to military time?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Expert Comment

by:eozz_2000
Comment Utility
Well, I use this function:

        Dim strTime As String = "5:15 PM"
        If strTime.Chars(strTime.Length - 2) = "P" Then
            If CInt(strTime.Substring(0, strTime.IndexOf(":"))) <> 12 Then
                MsgBox((CInt(strTime.Substring(0, strTime.IndexOf(":"))) + 12) & ":" & strTime.Substring(strTime.IndexOf(":") + 1, 2))
            Else
                MsgBox("12:" & strTime.Substring(strTime.IndexOf(":") + 1, 2))
            End If
        ElseIf CInt(strTime.Substring(0, strTime.IndexOf(":"))) = 12 Then
            MsgBox("00:" & strTime.Substring(strTime.IndexOf(":") + 1, 2))
        Else
            MsgBox(strTime.Substring(0, strTime.Length - 3))
        End If

In the documentation of Visual Basic say that you can use format(date,"Short Time") but it don't work for me.
I hope this could help you :)
0
 
LVL 10

Expert Comment

by:Hans Langer
Comment Utility
repeated thread ? :D

Dim MyDateTime As Date = #1/27/2001 5:04:23 PM#
MyStr = Format(MyDateTime, "hh:mm:ss tt")   ' Returns "05:04:23 PM".
MyStr = Format(MyDateTime, "HH:mm:ss")   ' Returns "17:04:23"
0
 

Author Comment

by:sticar
Comment Utility
I actually asked about a month conversion one on this one.  And thought I should ask the other question in another thread.
0
 
LVL 10

Accepted Solution

by:
123654789987 earned 250 total points
Comment Utility
If u want to do the month conversion then u can do it this way..

Dim strDate As String = Month.Selection.Text & "/" & Day.Selection.Text & "/" & Year.Selection.Text

Dim convertDate As String = Convert.ToDateTime(strDate).ToString("MM/dd/yyyy");

now if u check the value of convertDate it will be in the format 10/14/2004
0
 

Author Comment

by:sticar
Comment Utility
That's what I needed.
Thanks!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now