Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Date Verifier in VB

Posted on 2001-08-14
12
Medium Priority
?
433 Views
Last Modified: 2010-08-05
In SQL there is a command ISDATE(YYMMDD) which returns 1 if the parameter is a date and 0 if it is not a valid date.  

I am looking for a built in Visual Basic function which will allow me to pass in a 6 character field and return either true or false depending on whether or not the string is a valid date.

Here are a few examples
"770705"  => True, This is July 5, 1977
"840010"  => False, there is no Month
"000101"  => True, This is January 1, 2000
"01B0pH"  => False, This is garbage data


If any one can tell me the VB equivalant to the SQL isdate command, I will reward them the points.  It is that simple...
Thanks


0
Comment
Question by:ifgtest001
[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
12 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 6384039
There is an isdate function in VB. However it does require that there is some seperator in the expression to be evaluated so:

IsDate("770705") = False
IsDate("77-07-05") = True

But all is not lost, you can easily convert the 6 character string into an acceptable date format using:

IsDate(format("770705","yy-mm-dd")) = True
0
 
LVL 6

Expert Comment

by:VK
ID: 6384054
try that:

exaple

isdate(format("980505","yy/dd/mm")) = true !
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6384090
Beat you VK! It doesn't actually matter what the seperator is as long as it is a valid date seperator somewhere.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 22

Expert Comment

by:ture
ID: 6384447
Is this really correct??? I'm trying this in Excel VBA, but it really doesn't work the way you imply.

Please correct me if I'm wrong...

Try this in the immediate window:
?format("980505","yyyy/dd/mm")

It really doesn't show us the date 1998-05-05!
It shows us the date that is 980505 days from January 1 1900 - which is 4584-11-07.

To verify that "980505" is a date, you must insert separators and check if it's a date. This will work for a 6-digit YYMMDD date:

function isitadate(d as string) as boolean
  isitadate = isdate(mid(d,1,2) & "-" & mid(d,3,2) & "-" & mid(d,5,2))
end function

Ture Magnusson
Karlstad, Sweden
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6384517
>In SQL there is a command ISDATE(YYMMDD) which returns 1
>if the parameter is a date and 0 if it is not a valid date.

You might want to clarify which SQL environment you are speaking. The syntax, keywords, and functions differ from one DBMS to another. You don't do things exactly the same way in MS Access SQL as you do in MS SQL Server, or in Oracle SQL.

Ture is correct in the fact that the first couple of suggestions would return a date, but not the one you expected.

-Dennis Borg
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6384547
I didn't actually test that the date determined was what it should have been, thanks ture for the extra mile.
0
 
LVL 2

Expert Comment

by:AndrewK
ID: 6385016
... or the extra instruction: FormatDateTime(mydate, date_format) where date_format would be vbShortDate in the above examples.
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6385326
Adding to previous comments, Try this:

Private Function CheckIfDate(MyDate As String)
Dim sDate As String

MyDate = "770705"

sDate = Left(MyDate,2) & "-" & Mid(MyDate,3,2) & "-" & Right(MyDate, 2)

CheckIfDate = IsDate(sDate)
End Sub

'Hope this helps.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6385626
? IsDate(Format("981005", "@@/@@/@@"))
True

' insert  /  characters
?Format("981005", "@@\/@@\/@@")
98/10/05

' insert date separators
?Format("981005", "@@/@@/@@")
98/10/05
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6385641
ifgtest001:

Here is an example illustrating how you can perform your check:


   IsDate(Format("770705","00/00/00"))

This will return either true or false

The only "thing" would be if you had dates such as the following:

   "010203"

Which should it be:

    Jan 02, 2003
    Feb 01, 2003
    Feb 03, 2001
    etc.

It is a little ambiguous, but doesn't change the fact of whether or not it is a valid date.


-Dennis Borg
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7199948
Hi ifgtest001,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Save as PAQ -- No Refund.
    *** Too many excellent answers; too few points to split

ifgtest001, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7213439
Per recommendation, points NOT refunded and question closed.

Netminder
CS Moderator
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

604 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