Solved

vb.net convert non numeric date to numeric date

Posted on 2014-02-18
2
315 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
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

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.

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

770 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