Solved

Format String to Date

Posted on 2004-10-14
10
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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