Solved

Check Date formats before updating database

Posted on 2006-07-21
3
170 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

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

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 …
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.
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

10 Experts available now in Live!

Get 1:1 Help Now