?
Solved

Check Date formats before updating database

Posted on 2006-07-21
3
Medium Priority
?
176 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
[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
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 2000 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

Industry Leaders: 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!

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

752 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