Solved

Format String to Date

Posted on 2004-10-14
10
180 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
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!

 

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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