Solved

vb.net convert non numeric date to numeric date

Posted on 2014-02-18
2
319 Views
Last Modified: 2014-02-18
I couldn't find a lot of documentation on this.

I have a non standardized database that I am trying to tame.  I have a lot of dates in written format (July 3, 2013 ) for example.  I only want the month and year for this and I would like to automate this process.

What is the best way to take that string and convert it to a date format?
0
Comment
Question by:gwarcher
[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
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39868964
You can use the standard DateTime.TryParse() method and pass in the English culture like below.  Then pass in your desired format to ToString() to get just the month/year:
        Dim en As New System.Globalization.CultureInfo("en-US")

        Dim strDateFromDatabase As String = "July 3, 2013"
        Dim dt As Date

        ' ... loop thru the database rows ...

            If DateTime.TryParse(strDateFromDatabase, en, Globalization.DateTimeStyles.None, dt) Then
                Dim strFormattedDate As String = dt.ToString("MMyyyy")
                MessageBox.Show(strFormattedDate)
                ' ... do something with "strFormattedDate" ...
            Else
                MessageBox.Show(strDateFromDatabase, "Error Parsing Date")
            End If

Open in new window

0
 

Author Closing Comment

by:gwarcher
ID: 39869399
thanks!
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

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 …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 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