Solved

Format String to Date

Posted on 2004-10-14
10
177 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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 250 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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