Solved

vb.net convert non numeric date to numeric date

Posted on 2014-02-18
2
312 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
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
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
Comment Utility
thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now