473,549 Members | 2,982 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

validating Dates and Times

I am currently trying to validate data in an access database. I need
to verify that columns containing date information are in the format
ddmmyyyy and columns containg time information are in the format HH:MM
24. The dates and times are stored in text fields. ie date 12121998,
time 20:34

Could anyone suggest a method for validating the fields. What is the
syntax for converting text fields into dates and times?

Any suggestions welcomed. Thanks in advance
Nov 12 '05 #1
5 5978
I recently experienced a similar problem although I was not able to
find a satisfactory solution. Lets hope that atleast one person has
some ideas.
Nov 12 '05 #2
"Steve" <st************ ****@hotmail.co m> wrote in message
news:ed******** *************** ***@posting.goo gle.com...
I am currently trying to validate data in an access database. I need
to verify that columns containing date information are in the format
ddmmyyyy and columns containg time information are in the format HH:MM
24. The dates and times are stored in text fields. ie date 12121998,
time 20:34

Could anyone suggest a method for validating the fields. What is the
syntax for converting text fields into dates and times?

Any suggestions welcomed. Thanks in advance

You will really have to write your own function for this. You need to
consider whether the length would have to be exactly 8 characters, or
whether 010103 (only 6 characters) is valid and means January 1, 2003. You
should also consider whether there are any dates which cannot be valid - for
example should an order date of 01011492 be viewed with suspicion?
For example, the function below not only checks if the date is valid (must
be exactly 8 characters) but also that it occurs between 1980 and 2003 if it
does, a date is returned, otherwise the function returns null.

HTH

Fletcher

Public Function GetDate(varDate ) As Variant

On Error Resume Next

Dim dte As Date
Dim var As Variant

var = Null

If Len(varDate) = 8 Then
dte = DateSerial(CInt (Right(varDate, 4)), _
CInt(Mid(varDat e, 3, 2)), _
CInt(Left(varDa te, 2)))
End If

If Err.Number = 0 Then
If dte > DateSerial(1980 , 1, 1) And _
dte < DateSerial(2004 , 1, 1) Then _
var = dte
End If

GetDate = var

End Function
Nov 12 '05 #3
st************* ***@hotmail.com (Steve) wrote in
news:ed******** *************** ***@posting.goo gle.com:
I am currently trying to validate data in an access database.
I need to verify that columns containing date information are
in the format ddmmyyyy and columns containg time information
are in the format HH:MM 24. The dates and times are stored in
text fields. ie date 12121998, time 20:34

Could anyone suggest a method for validating the fields. What
is the syntax for converting text fields into dates and times?

Any suggestions welcomed. Thanks in advance

The dateserial and timeserial functions are one way.

My_date = dateserial(righ t(text1,4),mid( text1,3,2),left (text1,2))+
timeserial(left (text2,2),right (text2,2),0)
Bob Q
Nov 12 '05 #4
st************* ***@hotmail.com (Steve) wrote in message news:<ed******* *************** ****@posting.go ogle.com>...
I am currently trying to validate data in an access database. I need
to verify that columns containing date information are in the format
ddmmyyyy and columns containg time information are in the format HH:MM
24. The dates and times are stored in text fields. ie date 12121998,
time 20:34

Could anyone suggest a method for validating the fields. What is the
syntax for converting text fields into dates and times?

Any suggestions welcomed. Thanks in advance


I'm almost afraid to ask this, but why not just store them as normal
date/time fields in Access and then use date math to convert them to
some other format by using a query? Seems like you're making work for
yourself by working against the way the database works. Only way of
validating the fields like that is to use a function in the
BeforeInsert event of your form and disallow adding records directly
to the table.

See CDate()and DateSerial().
Nov 12 '05 #5
TC
st************* ***@hotmail.com (Steve) wrote in message news:<ed******* *************** ****@posting.go ogle.com>...

(snip)
I need to verify that columns containing date information
[in a text field] are in the format ddmmyyyy


Why? Store dates in Date fields: that is what Date fields are for.
When you want to display them, use the Format property to make them
look however you want. That is what the Format property is for.

HTH,
TC
Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2556
by: John Livermore | last post by:
In C# what is the best way to validate that a particular string entered by a user will actually convert to a date w/o using a try catch block or writing code to explicitly parse the string? Here is what I know I can use, but there are potentially thousands of dates to validate, and I know this code is inefficient if there are lots of dates...
1
1663
by: Jorge EA | last post by:
Hi there, According to the following article, a textbox for a date entry field can be validated with a CompareValidator: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskvalidatingagainstdatatype.asp My question is: which date format would the validator consider correct, the one on the web server or the...
4
1480
by: John | last post by:
Hi I have a web control text box on my webform which I want to use for entering dates. Is there a way to validate this text box field for valid dates? May be using a validators such as regular expression validator? Thanks Regards
11
1332
by: tshad | last post by:
I have 4 dropdown boxes (fromDay, fromMonth, ToDay and ToMonth) I want to be able to test to make sure that the dates are valid and the the From dates are < the To dates. When I add the records to the database, I typically use something like: FromMonth.SelectedValue & "/01/" & FromYear.SelectedValue I also have other validators on the...
2
3690
by: Patrick.O.Ige | last post by:
I'm using this CompareValidator to validate dates but my default its mm/dd/yyyy <asp:CompareValidator ControlToValidate="DOB" Display="Dynamic" Text="Invalid birth date!" Operator="DataTypeCheck" Type="Date" Runat="Server" ID="DOBcompval" /> Is there a way i can change it to dd/mm/yyyy of course if not using RegularExpressionValidator Any...
1
11595
by: Don G | last post by:
Each entry in a data file includes date and time in text format - e.g. "0601271325" = 2006, January 27th, 1:25 pm. Is there a simple way to calculate the hours (including decimal parts) between two of these entries?
1
1529
by: =?Utf-8?B?Ym9iYnk=?= | last post by:
I have a textBox Where I type date. I want to validate it. Im using customValidate controls. I have this function in my code behind page void DatesValidate(object source, ServerValidateEventArgs e) { if (Convert.ToDateTime(e.Value) <= DateTime.Now) { e.IsValid = false; this.lblAddUsers.Text = "The Proxy is already expired"; }
1
1263
by: =?Utf-8?B?cmF1bGF2aQ==?= | last post by:
Hi: (I know there are lots of different ways to do it) no regex, please if we have string date yyMMdd "080230" whats the best way to test for valid date ? Feb will never have 30 days, 2) if we have string HHmm "3490" whats the best way to test for valid time? (worng hours wrong minutes)
2
1598
by: Just Me | last post by:
Hi people. I am attempting to determine how best to prevent a users date entry in an update action from causing a format exception. The dates are UK, but the user may try to put in a 'US' format. I have a datasource which is wired to my DAL/update function. 1.) On the server side.
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7715
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.