Solved

Check Date formats before updating database

Posted on 2006-07-21
3
171 Views
Last Modified: 2010-04-23
What is the best way to check for formatting of dates in a vb form before it get send to the db?

I was considering the text change on the field, but not sure that's the best way.

Code sample would be great.

Thanks in advance.

Tim
0
Comment
Question by:TimSweet220
  • 2
3 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17154234
Hi TimSweet220,

do you want to check the format or check the date is valid?

you could just check it is valid and then strip it into the format you want:

If IsDate(strDate) then
    //Do something
Else
   //not valid date
End If


Apresto
0
 
LVL 23

Expert Comment

by:apresto
ID: 17154237
the universally accepted date format is yyyy/mm/dd, i would recommend you use that format
0
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 500 total points
ID: 17154259
If you're going to update the DB on a button click and want to validate the date before that, I would suggest using the .Leave event.

    Private Sub txtDate_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDate.Leave
        If txtDate.Text = Nothing Then
            Exit Sub
        ElseIf Not IsDate(txtDate.Text) Then
            MessageBox.Show("The date is invalid!", "Invalid Date", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
            txtDate.Focus()
            txtDate.SelectAll()
            Exit Sub
        End If
    End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Iterate a dictionnary to change values 4 53
Vb.Net Date Formatting Assistance 4 35
Change Format on Data when exporting to Excel 4 23
SQL syntax in VB.net 5 30
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

13 Experts available now in Live!

Get 1:1 Help Now