Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Format String to Date

Posted on 2004-10-14
10
Medium Priority
?
185 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
ID: 12310259
what control does

Month.Selection.Text

come from?
0
 

Author Comment

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

Expert Comment

by:bramsquad
ID: 12310422
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sticar
ID: 12310568
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
ID: 12310614
What about a string that = "1:00 PM" or "1:00 AM" to change to military time?
0
 
LVL 4

Expert Comment

by:eozz_2000
ID: 12312939
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
ID: 12313935
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
ID: 12314412
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 1000 total points
ID: 12316533
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
ID: 12320661
That's what I needed.
Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Screencast - Getting to Know the Pipeline

876 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